Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

php - 如何在PHP中回显或打印数组?(How to echo or print an array in PHP?)

I have this array

(我有这个数组)

Array
(
  [data] => Array
    (
      [0] => Array
        (
          [page_id] => 204725966262837
          [type] => WEBSITE
        )

      [1] => Array
        (
          [page_id] => 163703342377960
          [type] => COMMUNITY
        )
      )
)

My question is how can I just echo the content without this structure?

(我的问题是如何在没有这种结构的情况下回复内容?)

I tried

(我试过了)

foreach ($results as $result) {
    echo $result->type; 
    echo "<br>";
} 
  ask by EnexoOnoma translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To see the contents of array you can use.

(要查看可以使用的数组内容 。)

1) print_r($array);

(1) print_r($array);)

or if you want nicely formatted array then:

(或者如果你想要格式良好的数组,那么:)

echo '<pre>'; print_r($array); echo '</pre>';

2) use var_dump($array) to get more information of the content in the array like datatype and length.

(2)使用var_dump($array)获取数组内容的更多信息,如数据类型和长度。)

3) you can loop the array using php's foreach();

(3)你可以使用php的foreach();循环数组foreach();)

and get the desired output.

(并获得所需的输出。)

more info on foreach in php's documentation website:

(有关foreach的更多信息,请访问php的文档网站:)
http://in3.php.net/manual/en/control-structures.foreach.php

(http://in3.php.net/manual/en/control-structures.foreach.php)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...