How to print an array in PHP? 1) print_r() function: 2) var_dump() function: 3) json_encode() function: 4) foreach() loop: Introduction An array is one kind of data structure, which can store multiple items of related data types. The printing of an array is one of the fundamen...
Theprint_rPHP function is used to return an array in a human readable form. It is written as: print_r($your_array) In this example, an array is defined and printed. The tagindicates the following code is preformatted text. This tag causes the text to be displayed in a fixed-width fo...
Usevar_dump()Function to Echo or Print an Array in PHP Thevar_dump()function is used to print the details of any variable or expression. It prints the array with its index value, the data type of each element, and length of each element. It provides the structured information of the ...
var_dump($arr); “` (3)最后,在浏览器中运行PHP脚本,就能够看到数组的输出结果。 方法二:使用print_r()函数 print_r()函数也是PHP内置的一个调试函数,它可以以更加人类可读的方式打印出变量的内容。下面是使用print_r()函数输出数组的操作流程: (1)首先,创建一个数组。例如,要输出一个包含字符串”apple”...
PHP array_flip() 函数 反转数组中的键名和对应关联的键值: $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $result=array_flip($a1); print_r($result); /** * in_array is too slow when array is large */ ...
<?php // 定义一个数组 $array = array("apple", "banana", "orange", "grape"); // 定义要查找的值 $value_to_find = "orange"; // 使用in_array()函数检查值是否存在于数组中 if (in_array($value_to_find, $array)) { echo "找到了值:" . $value_to_find; } else { echo "没有找...
PHP手册Array数组大全(解析) //array_change_key_case() $age=['cyg'=>"kkk","liwen"=>"70"]; print_r(array_change_key_case($age,CASE_UPPER));//把键名转换成大写,默认是小写 1. 2. 3. //array_chunk() $cars=array("Volvo","BMW","Toyota","Honda","Mercedes","Opel");...
<?php//创建一个简单的数组$array =array(1, 2, 3, 4, 5);print_r($array);//现在删除其中的所有元素,但保持数组本身不变:foreach ($arrayas$i =>$value) {unset($array[$i]); }print_r($array);//添加一个单元(注意新的键名是 5,而不是你可能以为的 0)$array[] = 6;print_r($array...
in_array() 是判断 值 在不在指定的数组里 第二个参数是个数组 第一个参数是具体值。识别是假就是说在$sel里没有找到1,1是整形 可以先 intval($se)求整一下 再判断 sel[0]有值(传的值),但是$caizi里没有$caizi[0] 你用的6做的下标,应该输出的array[6]看看识别结果 ...
In this post, I will share a short and simple code on how to print and write array values to files in PHP. If you have a task or problem that needs to write the array value to a file then this is for you. In this example, I'm using file_put_contents() to