1. 使用print_r()函数: print_r()函数是一种用于输出变量信息的调试工具,可以方便地打印出数组的内容和结构。例如: “`php $array = array(‘apple’, ‘banana’, ‘orange’); print_r($array); “` 输出结果为: “` Array ( [0] => apple [1] => banana [2] => orange ) “` 2. 使用...
array(3) { [0]=> string(5) “apple” [1]=> string(6) “banana” [2]=> string(6) “orange” } “` 通过以上示例可以看出,echo输出数组时只能输出数组的某个值,而print_r和var_dump函数可以将整个数组输出。 值得注意的是,print_r和var_dump函数主要用于调试和开发,不适合在正式环境中使用。在...
对PHP中的数组元素进行输出可以通过输出语句来实现,如echo,print语句等,但这种输出方式只能对某数组中的某一元素进行输出。而通过print_r()函数可以将数组结构进行输出。<?php header("Content-Type:text/html;charset=utf-8;"); $array[1]="汇"; $array[2]="智"; $array[3]="网"; print_r($array)...
print_r($end_array); function text_to_array($str) { //Initialize arrays $keys = array(); $values = array(); $output = array(); //Is it an array? if( substr($str, 0, 5) == 'Array' ) { //Let's parse it (hopefully it won't clash) $array_contents = substr($str, 7,...
echo ,print的区别在于echo 可以输出多个变量值,而print只有一个变量,做为一个字符串输出. 另一点区别在于echo 没有返回值,print有返回值1.print不能输出数组和对象。 print_r可以输出stirng、int、float、array、object等,输出array时会用结构表示,print_r输出成功时返回true; ...
print(""); ?> 上面的数组将输出如下: 让我们试着显示上面数组中的某个值: echo $sites['runoob'][0].'地址为:'.$sites['runoob'][1]; 上面的代码将输出: 三维数组 三维数组是在二维数组的基础上再嵌套一层数组,格式如下: array(array(array(elements...),array(elements...),...),array(array...
array_push(array, value1, value2, ...)其中,array 是要添加元素的数组,value1, value2, ... 是要添加到数组末尾的一个或多个元素。下面是一个例子:$fruits = array("apple", "banana");array_push($fruits, "orange", "pear");print_r($fruits);这段代码会输出:Array( [0] => apple ...
$output .= ',';30. } 31.32. return $output;33. } 34. function print_a(array $arr){ 35. $output = get_output_str1($arr);36. $output = 'array(' . $output . ')';37. echo $output;38. } 39.40. print_a($arr);
PHP函数printarray()缺点: 不能输出对象 print_r()可以输出对象 printarray($_REQUEST); function printarray($strs, $numbers=0) { $space=''; //输出字符前的空格 for($i=0;$i<$numbers * 2;$i++) $space.=' '; echo 'Array'.$space.'('; foreach ($str...
<?php$a = ['php', 'mysql', 'html'];echo "";print_r($a);?> 以上代码在PHP8中的运行结果为:Array( [0] => php [1] => mysql [2] => html)2、使用 array() 函数创建数组 使用 array() 函数创建一个新的数组,该数组接受任意数量用逗号分隔的键(key)=>值(value)对,语法...