dongming6201 2013-02-12 12:06
浏览 57

要打印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.

  • 写回答

2条回答 默认 最新

  • duanpen9294 2013-02-12 12:17
    关注

    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]);
            }
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算