My database query is below.
我的数据库查询如下。
$beneficiary_id = DB::select('select Telephone from item ');
This returns a json array looks like this
这将返回一个类似于此的json数组
[{"Telephone":"0111222333"},{"Telephone":"0112211223"},{"Telephone":"012345557"},{"Telephone":"0225545455"}]
For another database insertion operation I need only the telephone numbers. I have used json_decode()
function, it is working only if we enter the array manually.
对于另一个数据库插入操作,我只需要电话号码。我使用了json_decode()函数,它只在我们手动输入数组时才有效。
How to get only those values to another array?
如何只将这些值传递给另一个数组?
Thanks in advance.
提前致谢。
2 个解决方案
#1
2
Use the pluck function
使用拔除功能
If you would like to retrieve an array containing the values of a single column, you may use the pluck method.
如果要检索包含单个列的值的数组,可以使用pluck方法。
$titles = DB::table('roles')->pluck('title');
foreach ($titles as $title) {
echo $title;
}
#2
0
use $beneficiary_id->column_name to get the value from your object.
使用$ beneficiary_id-> column_name从对象中获取值。
#1
2
Use the pluck function
使用拔除功能
If you would like to retrieve an array containing the values of a single column, you may use the pluck method.
如果要检索包含单个列的值的数组,可以使用pluck方法。
$titles = DB::table('roles')->pluck('title');
foreach ($titles as $title) {
echo $title;
}
#2
0
use $beneficiary_id->column_name to get the value from your object.
使用$ beneficiary_id-> column_name从对象中获取值。