在php中从数组中提取数据
如何从该阵列提取数据:在php中从数组中提取数据,php,arrays,Php,Arrays,如何从该阵列提取数据: Array ( [0] => Array ( [name] => color / size [value] => Array ( [0] => blue / l [1] => blue / m [2] => r
Array
(
[0] => Array
(
[name] => color / size
[value] => Array
(
[0] => blue / l
[1] => blue / m
[2] => red / l
[3] => red / m
)
}
用这种格式
color = blue,red
size = L,M
使用和将解决此问题。试试这个:
foreach ($array[0]['value'] as $k => $val) {
$values = explode(' / ', $val); // Break up string into array
$color[] = $values[0]; // Store colors in this array
$size[] = $values[1]; // Store size in this array
}
echo 'Color = ' . implode(',', array_unique($color)); // First get unique values using array_unique, then convert this array to string using implode()
echo '<br/>';
echo 'Size = '. implode(',', array_unique($size)); // First get unique values using array_unique, then convert this array to string using implode()
显示整个最终阵列的外观