0

my problem is i have this array :

$stockImages = [
    [
        'name' => $large, 
        'type' => 'large', 
        'resolution' => $w.'x'.$h, 
        'size' => $lSize 
    ]
]

I want to get this value $w i tried with it

{{$stockImages[1]->resolution($w)}}

but it didn't work

4
  • Few problems: 1. Array index start from 0, your array has 1 element so should be $stockImages[0] 2. You are accessing resolution like a property in an object, change to $stockImages[0]['resolution'] 3. you already concat the $w and $h so it's now a string, try explode('x') to split the w and h Commented Oct 5, 2020 at 23:32
  • i tried with it {{$stockImages[0]->resolution(explode('', $w))}} but nothing Commented Oct 5, 2020 at 23:40
  • this question is too basic, i suggest you start with a php guide. -> is object notation and it doesnt apply to arrays. Commented Oct 5, 2020 at 23:42
  • as this $stockImages[1]->resolution i receive a value good but i receive the width and height i want only $w width Commented Oct 5, 2020 at 23:47

1 Answer 1

2

you are getting too complicated, try this:

$stockImages = [[
    'name' => $large, 
    'type' => 'large', 
    'resolution' => 
        [
            'w' => $w, 
            'x' => $h
        ],
    'size' => $lSize 
]];

and done, access to width like this way:

$stockImages[0]['resolution']['w'];

bye <3

http://sandbox.onlinephpfunctions.com/code/cd60316ace8e386a9e49b22bf95aa7123605b92e

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

Comments

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.