2

Helper, I can fetch value of fname, lname and so on.., But I'm struggling to fetch value of address1, city.., where my array is,

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
                )
        )
)

3 Answers 3

1

If you really want to this in Laravel way, you can use a collection.

Here is an example

 $collection = collect(Your array);

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

Hope this helps

Sign up to request clarification or add additional context in comments.

Comments

0

You need to iterate over subarray, for example:

@foreach ($array['addresses'] as $address)
    {{ $address['city'] }}
    {{ $address['address1'] }}
@endforeach

4 Comments

But brother I can get only value of [0] what to do for [1]
@SamuelHenry this code should print city and address1 for all addresses in the array.
sry don't mistake me, For example, only I'm getting {address1} value as {somewhere}. I wanna get both {somewhere} and {someplace}. foreach should do but It not..,
Sry, @Alexey Mezenin, actually I also has another error so y I got that. Thanks mr...
0

You can access by $baseArray['addresses'][0]['address1'] and so on.

But what you probably want is something like:

@foreach ($array as $baseArray['addresses'])
    {{ $address['city'] }}
    {{ $address['address1'] }}
@endforeach

1 Comment

Thanks bro yours first one is working, second code is with an error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.