wordpress - Accessing WP cron multidimensional array efficiently in PHP -


i need access multiple arrays, problem lies when arrays need below, can't access traditionally because key different every time.

i'm dealing following array:

array (     [oe_schedule_charge] => array         (             [617cdb2797153d6fbb03536d429a525b] => array                 (                     [schedule] =>                      [args] => array                         (                             [0] => array                                 (                                     [id] => cus_2opctp95lw8smv                                     [amount] => 12                                 )                          )                  )          )  ) 

there going hundreds of these arrays , need way efficiently access data within them. i'm using following code expected output:

function printvaluesbykey($array, $key) {     if (!is_array($array)) return;     if (isset($array[$key]))          echo $key .': '. $array[$key] .'<br>';     else         foreach ($array $v)             printvaluesbykey($v, $key); }  $cron = _get_cron_array();  foreach( $cron $time => $hook ) {     if (array_key_exists('oe_schedule_charge', $hook)) {         echo '<div>';         echo date('d f d y', $time);         echo printvaluesbykey($hook, 'amount');         echo printvaluesbykey($hook, 'id');         echo '</div>';     } } 

but i've never had deal data, take proper precautions. light can shed on accessing multidimensional array in efficient way appreciated.

i consider loading object, writing member functions want.

class myclass {   private $_uniquekey; private $_schedule; private $_args = array();  private $_amount = array(); private $_id = array();  public function __construct($arraything) {     foreach($arraything['oe_schedule_charge'] $uniquekey => $dataarray)     {         $this->_uniquekey = $uniquekey;         $this->_schedule = $dataarray['schedule'];         $this->_args = $dataarray['args'];     }     $this->_afterconstruct(); }  private function _afterconstruct() {     foreach($this->_args $argitem)     {         if(isset($argitem['amount']) && isset($argitem['id']))         {             $this->_amount[] = $argitem['amount'];             $this->_id[] = $argitem['id'];         }     } }  public function getuniquekey() {     return $this->_uniquekey; }  public function getschedule() {     return $this->_schedule; }  public function getargs() {     return $this->_args; }  public function printshitout($time) {     //you define this. if print_r( on object, tell items need. )  }  //code this:  $cron = _get_cron_array();  foreach( $cron $time => $hook )  {     $obj = new myclass($hook);     $obj->printshitout($time); } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -