Array related question

I am trying to print an array. All code works fine. But finally I get `ArrayArray '. Can anyone solve this problem. many thanks

here is my array

Array
(
[Post1] => Array
    (
        [id] => 1
        [title] => hi
    )
[Post2] => Array
    (
        [0] => Array
            (
                [id] => 1
            )
    )
[Post3] => Array
    (
        [0] => Array
            (
                [id] => 1
            )
    )
 )

Here is my PHP code

foreach($post as $key => $value) {
 foreach($value as $print => $key) {
     echo "<br>".$key;
   }
}

displayed here

ID
Array
Array
+3
source share
4 answers

Try the following:

foreach($post as $key => $value) {
 foreach($value as $print => $key) {
     if (is_array($key)){
         foreach($key as $print2 => $key2) {
          echo "<br>".$key2;
          }

     }else{
     echo "<br>".$key;
     }
   }
}
+3
source

The string method for the array should return "Array".

It looks like you want to view the array for debugging purposes. var_dump()- your friend:)

0
source

, Array. , print_r

0

, , $ $ , $, .

, ?

echo "<pre>" . print_r( $post , true ) . "</pre>\n";
0

All Articles