要打印array.under数组的值

I have to print the all the value of the array written value.

[subscriber] => Array
    (
        [name] => Subscriber
        [capabilities] => Array
            (
                [read] => 1
                [level_0] => 1
            )
        [default] => Array
            (
                [deft] => Array (
                              [one] => 2
                              [two] => 3
                        )
                [deft_one] => Array (
                               [one] => t
                               [two] => h
                        )
            )

    )

I have to print each value under the array. So i used a recursion function. But i cant the result. Please help me in recursion function.

Sorry, I am trying till now. Actually i have to print the wp-option table value. There are many serialise array. I want to print all the value individually. I mean when i used the code written bellow i got an array.

function option_value_change () {
  global $wpdb;
  $myrows = $wpdb->get_results( "SELECT *
  FROM `wp_options`");
    $temp_url = get_option('siteurl');
    $site_url = get_site_url();
    foreach ($myrows as $rows){
      $option = get_option($rows->option_name);
                //print_r($option);
        get_option_value($option);
    }
}

i can get the table. But in an array. Which array have arrays. So i used an function "get_option_value($option)". as written bellow

function get_option_value($option) {
    if(!is_object($option) && !is_array($option)){
        echo $option;
    }
    else{
            foreach($option as $option_value){
                if(!is_array($option_value)){
                    echo $option_value;
                }
                else {
                    get_option_value($option_value);

                }
            }
    }
}

bUt i cant get all the value. its give an error as

Object of class stdClass could not be converted to string.

So how can i print all the values of the array.

dpxbc88022
dpxbc88022 你现在能解决我的问题吗?
7 年多之前 回复
doubi4617
doubi4617 把你的功能。告诉它哪里出错了。显示你想要的东西。
7 年多之前 回复
doutou7740
doutou7740 我们能看到你的递归函数吗?
7 年多之前 回复

2个回答

You can use RecursiveArrayIterator example :

$data = array(
  'subscriber' => array(
    'name' => 'Subscriber',
    'capabilities' => array(
      'read' => 1,
      'level_0' => 1,
    ),
    'default' => array(
      'deft' => array(
        'one' => 2,
        'two' => 3,
      ),
      'deft_one' => array(
        'one' => 't',
        'two' => 'h',
      ),
    ),
  ),
);

echo "<pre>";
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($data));
foreach($it as $var)
{
    echo $var , PHP_EOL ;
}

Output

Subscriber
1
1
2
3
t
h
douhui9192
douhui9192 可以看到我编辑的问题吗? 我现在使用你的代码“echo”<pre>“; $ it = new RecursiveIteratorIterator(new RecursiveArrayIterator($ option)); foreach($ it as $ var){echo $ var,PHP_EOL;}
7 年多之前 回复
douchuose2514
douchuose2514 什么错误? ....
7 年多之前 回复
dps123456789
dps123456789 谢谢你的帮助。 但是当我使用你的代码时,它会给出一个错误,比如Uncaught异常'InvalidArgumentException',消息'Passed variable不是数组或对象,而是使用空数组代替
7 年多之前 回复

I didn't test it but you can get the idea;

function printArr($obj){

    if(!is_array($obj)){

        echo $obj;
        return;
    }
    else if(is_array($obj)){

        foreach ($obj as $key => $value) {
            printArr($obj[$key]);
        }
    }
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐