简体   繁体   English

如何在codeigniter视图中预测此数组结果和回显

[英]How can i foreach this array result and echo in codeigniter view

foreach this array result and echo the results foreach这个数组结果并回显结果

Array
(
[0] => Array
    (
        [0] => Array
            (
                [blog_title] => sooraj bloging
                [blog_id] => 2
            )

        [1] => Array
            (
                [blog_title] => What are Mobile App Testing Challenges?
                [blog_id] => 4
            )

        [2] => Array
            (
                [blog_title] => sooraj blog
                [blog_id] => 8
            )

    )

[1] => Array
    (
        [0] => Array
            (
                [title] => sooraj casestudy
            )

    )

[2] => Array
    (
        [0] => Array
            (
                [career_id] => 14
                [title] => Software Engineer .NET sooraj
                [location] => Kochi, India.
                [description] => Developing .NET applications. 
                [qualification] => B.Tech. in CSE, MCA
                [status] => 0
                [created_at] => 2017-11-20 13:14:29
                [updated_at] => 0000-00-00 00:00:00
            )

    )

[3] => Array
    (
    )

[4] => Array
    (
        [0] => Array
            (
                [tst_id] => 146
                [tst_name] => John Kasha
                [tst_quote] => Gadgeon was extremely professional and was easy to commun  sooraj icate and work with on a day-to-day basis. I also liked the fact that they were willing to do the research for specific tasks and present a viable solution or workaround to keep the project on schedule. I would recommend them for any task for any industry software or hardware. Bottom line, they get it done and you get results, not excuses. VP of Engineering.
                [tst_desig] => Vice President,Product Development and Engineering
                [tst_image] => 91c09ac9ee6234fdfcc523a393800bd5.jpg
                [url] => 
                [crop_name] => 668959f965ab28815dc97bbc1f8718d8.jpg
                [sysDate] => 2017-11-20 15:42:34
            )

    )

)

Just Run this code 只需运行此代码

        <?php
    $array = array(
                array(
                    array(
                        'blog_title' => 'sooraj bloging',
                        'blog_id' => 2
                    ),
                    array(
                        'blog_title' => 'What are Mobile App Testing Challenges?',
                        'blog_id' => 4
                    ),
                    array(
                        'blog_title' => 'sooraj blog',
                        'blog_id' => 8
                    )
                ),
                array(
                    array(
                        'title' => 'sooraj casestudy',
                    )
                ),
                array(
                    array(
                        'career_id' => 14,
                        'title' => 'Software Engineer .NET sooraj',
                        'location' => 'Kochi, India.',
                        'description' => 'Developing .NET applications.',
                        'qualification' => 'B.Tech. in CSE, MCA',
                        'status' => 0,
                        'created_at' => '2017-11-20 13:14:29',
                        'updated_at' => '0000-00-00 00:00:00'
                    )
                ),
                array(),
                array(
                    array(
                        'tst_id' => 146,
                        'tst_name' => 'John Kasha',
                        'tst_quote' => 'Gadgeon was extremely professional and was easy to commun  sooraj icate and work with on a day-to-day basis. I also liked the fact that they were willing to do the research for specific tasks and present a viable solution or workaround to keep the project on schedule. I would recommend them for any task for any industry software or hardware. Bottom line, they get it done and you get results, not excuses. VP of Engineering.',
                        'tst_desig' => 'Vice President,Product Development and Engineering',
                        'tst_image' => '91c09ac9ee6234fdfcc523a393800bd5.jpg',
                        'url' => '',
                        'crop_name' => '668959f965ab28815dc97bbc1f8718d8.jpg',
                        'sysDate' => '2017-11-20 15:42:34'
                    )
                )
            );

        foreach ($array as $value){
            foreach ($value as $row){
                foreach ($row as $key=> $row1){
                    echo $key.' - '. $row1;
                }
            echo '<br>';
            }
        }

    ?>

Depending what you're trying to do (debugging vs tabular display), you can "pretty print" the array with var_export like so: 根据您要执行的操作(调试与表格显示),您可以使用var_export “漂亮地打印”数组, var_export所示:

// Assuming your array is $data
echo '<pre>'.var_export($data, TRUE).'</pre>';

Otherwise, to loop through the array as is with a foreach : 否则,使用foreach循环遍历数组:

// Assuming your array is $data
foreach ($data as $subdata) {
    // You probably want to check that this is an array for case #3
    if(is_array($subdata)) {
         foreach ($subdata as $valueset) {
             // Check for array validity (not required for example data, but good to be safe)
             if (is_array($valueset)) {
                 foreach ($subdata as $key => $value) {
                     // Print each key, value pair as a row
                     echo $key .' => '.$value . '<br />';
                 }   
             }
         }
    } else {
        // Optional handling of empty set
        echo 'No data to display...';
    }
}
foreach  ($array as $value){
foreach  ($value as $row){
     if (is_array($row)){
            foreach  ($row as $key => $val){
                 echo $key."=>". $val."<br>";
             }///endForeach
         }///endIf
       else {
                echo $row;
      }////endElse
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM