充分利用数组一个特定的值 [英] Getting a specific value from array
本文介绍了充分利用数组一个特定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对mysql的这个查询,我得到这个数组的print_r():
I have this query on mysql, and i'm getting this array with print_r():
$data = Array ( [2] => Array ( [0] => Array ( [sale_order_value_id] => 3 [sale_order_id] => 2 [name] => Comprobante Fiscal [value] => Consumidor Final [price] => 0.0000 ) [1] => Array ( [sale_order_value_id] => 4 [sale_order_id] => 2 [name] => RNC / Cédula [value] => 00111936266 [price] => 0.0000 ) ) )
我想只提取【名称】从$每个输入数据,我都试过爆炸()来分隔值,但它不能帮助。
I want to extract just the [name] from $data for each input, i have tried explode() to separate the values but that does not help.
推荐答案
下面是做一个适当的方式:
Here is a proper way to do it :
示例:
<?php
// Array representing a possible record set returned from a database
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
$first_names = array_column($records, 'first_name');
print_r($first_names);
?>
OUTPUT:
Array
(
[0] => John
[1] => Sally
[2] => Jane
[3] => Peter
)
和是在你的情况下,可以也是这样的做,因为它很简单:
And Yes in your case it can be done like this way too as it is easy :
您code:
<?php
$data = array( 2 => array( 0 => array('name' => "John")));
//You can simply print the name column value like this
echo $data[2][0]["name"];
?>
您code输出:
John
带电作业链接你的$ C $的C: https://eval.in/565707
这篇关于充分利用数组一个特定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文