Answer the question
In order to leave comments, you need to log in
How to output a multidimensional array using recursion?
There is a table in which I display the values of an array, in this case a multidimensional array, I want to display all its elements using recursion, but it displays only one array.
code part: (controller):
$data = $logModel->getDetails($log_id);
$before = !is_null($data['value_before'])?unserialize($data['value_before']):null;
$after = !is_null($data['value_after'])?unserialize($data['value_after']):null;
$data = array(
'before' => $before,
'after' => $after,
'params' => !is_null($before) ? array_keys($before) : array_keys($after),
);
(View):
<? if(!is_null($this->data['params'
<? foreach ($this->data['params'] as $value):?>
<?= $value;?>
<?=(!is_null($this->data['before']) ? $this-> data['before'][$value] : 'not set')?>
<?=(!is_null($this->data['after'] ) ? $this->data['after'][$value ] : 'not set');?>
debug: <? Zend_Debug::dump($this->data['after'][$value] );die;?>
array(23) {
["id"] => int(14920)
["name"] => string( 25) "product for 1001(4)"
["currency"] => string(3) "UAH"
["url"] => string(16) "product-dlya-10014"
["type_id"] =>
["price"] => string(6) "0.0000"
["min_price"] => string(6) "0.0000"
["max_price"] => string(6) "0.0000"
["sku_id"] => int (15692)
["summary"] => string(0) ""
["meta_title"] => string(25) "item for 1001(4)"
["meta_description"] => string(0) ""
[" meta_keywords"] => string(0) ""
["description"] => string(0) ""
["cross_selling"] => int(0)
["upselling"] => int(0)
["sku_type" ] => int(0)
["skus"] => array(1) {
[15692] =>array(20) {
["id"] => int(15692)
["product_id"] => int(14920)
["id_1c"] => NULL
["sku"] => string(0) ""
[" sort"] => int(1)
["name"] => string(0) ""
["image_id"] => int(-1)
["price"] => string(6) "0.0000"
["primary_price"] => string(6) "0.0000"
["purchase_price"] => string(6) "0.0000"
["compare_price"] => string(6) "0.0000"
["count"] => NULL
["available"] => int(1)
["dimension_id"] => NULL
["file_name"] => string(0) ""
["file_size"] => int(0)
["file_description"] => string(0) ""
["virtual"] =>int(0)
["expected_date"] => string(0) ""
["sku_image_ext"] => NULL
}
}
}
code:
public function logArray($arr, $recurse) {
static $result = array();
foreach ($arr as $key => $v) {
if ($key == $recurse) $result[] = $v;
if (is_array($arr[$key])) $this->logArray($v, $recurse);
}
return $result ;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question