This article mainly share with you the method of PHP to take out an array of single values, mainly in the form of code and we share, hope to help everyone.
PHP takes out an array of single values
1. Array arr
The Var_dump (ARR) values are as follows:
Array (size=3) ' delete ' = = Array (size=3) 0 = String ' hbsflyrecode20170222-101501.txt ' (length=31) 1 = String ' Hbsflyrecode20170222-105502.txt ' (length=31) 2 = String ' Hbsflyrecode20170222-108803.txt ' (length=31) ' new ' = = Array (size=3) 0 = String ' hbsflyrecode20170223-101504.txt ' (length=31) 1 = String ' Hbsflyrecode20170223-105505.txt ' (length=31) 2 = String ' Hbsflyrecode20170223-108806.txt ' (length=31) ' old ' = = Array (size=3) 0 = String ' hbsflyrecode20170221-101507.txt ' (length=31) c13/>1 = String ' Hbsflyrecode20170221-105508.txt ' (length=31) 2 = String ' Hbsflyrecode20170221-108809.txt ' (length=31)
echo $arr [' old '][0]; print out: Hbsflyrecode20170221-101507.txt
However, if Arr is in the form of an object, the print results are as follows:
Var_dump (arr)
Object (StdClass) [1] public ' delete ' = = Array (size=3) 0 = String ' hbsflyrecode20170222-101501.txt ' (length=31) 1 = String ' Hbsflyrecode20170222-105502.txt ' (length=31) 2 = String ' Hbsflyrecode20170222-108803.txt ' (length=31) public ' new ' = Array (size=3) 0 = String ' Hbsflyrecode20170223-101504.txt ' (length=31) 1 = String ' Hbsflyrecode20170223-105505.txt ' (length=31) 2 = = String ' Hbsflyrecode20170223-108806.txt ' (length=31) public ' old ' = Array (size=3) 0 = String ' Hbsflyrecode20170221-101507.txt ' (length=31) 1 = String ' Hbsflyrecode20170221-105508.txt ' (length= 2 = String ' Hbsflyrecode20170221-108809.txt ' (length=31)
You cannot use $arr [' old '][0] to take a value, you can use ARR objects and arrays of common foreach methods:
function GetValue ($arr) { foreach ($arr as $key = = $value) { if (Is_array ($value)) { getValue ($value); } else{ echo $value. " <br> ";}} }
If Arr is in the form of an object, you can test the object into an array form, which provides a quick way to:
1. $object _json = Json_encode ($arr), the object $json = Json_encode ($arr, True), and the resulting pure json2. Json_decode ($object _json) and Json_decode ($json) Gets the array object Json_decode ($object _json,true) and Json_decode ($json, true) to get an array of arrays, the way the array objects can be converted to arrays:
Arr,true), true);
This problem is found in the project, it is recommended that when you convert JSON and array in PHP, the second parameter of Json_encode () and Json_decode () is added true, namely:
Json_encode (
Json,true);
"'