mysql - 我如何从 laravel 中的数组中获取值

标签 mysql arrays laravel

helper , 我可以获取 fname、lname 等的值..,但我正在努力获取 address1、city.. 的值,我的数组所在的位置,

Array
(
    [id] => 172
    [fname] => Someone
    [lname] => Sombody
    [gender] => Male
    [phno] => 0123456789
    [addresses] => Array
        (
            [0] => Array
                (
                    [id] => 71
                    [user_id] => 172
                    [address1] => somewhere
                    [city] => some city
                    [state] => some state
                    [country] => India
                )
            [1] => Array
                (
                    [id] => 72
                    [user_id] => 172
                    [address1] => someplace
                    [city] => specified city
                    [state] => specified state
                    [country] => India
                )
        )
)

最佳答案

如果你真的想以 Laravel 的方式做到这一点,你可以使用 collection

举个例子

 $collection = collect(Your array);

$filtered = $collection->only(['addresses']);
$filtered->all();
//it will return the your desired collection

希望对你有帮助

关于mysql - 我如何从 laravel 中的数组中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49049838/

相关文章:

mysql - 一次更新多个表的一列

php - mysql - 匹配日期时间字段的年份数组

mysql - 在存储过程中打印多行

c - 试图对结构中的数据进行排序,它排序正确但最后一行是错误的

python - 如何打印字典的所有子集?

php - laravel全文搜索多个关键字在一起

php - 如何使用 PHP 显示 mysql 表中包含空字段的行数?

php - 如何使用数据库实时创建 Laravel 图表包

javascript - 如何更新 laravel 中的 package-lock.json 文件?

javascript - 按特定的给定顺序对 JSON 数组进行排序