0

I'm working on a php magento script which have a array variable for store some script urls.

array variable $items['js']

var_dump

array(1) {
[""]=>
array(17) {
["prototype/prototype.js"]=>
string(22) "prototype/prototype.js"
["varien/form.js"]=>
string(14) "varien/form.js"
["mage/translate.js"]=>
string(17) "mage/translate.js"
["mage/cookies.js"]=>
string(15) "mage/cookies.js"
["wyomind/layer/native.history.js"]=>
string(31) "wyomind/layer/native.history.js"
["varien/weee.js"]=>
string(14) "varien/weee.js"
["geissweb/vatvalidation-min.js"]=>
string(29) "geissweb/vatvalidation-min.js"
}
}

I tried to access the "geissweb/vatvalidation-min.js" value like this

$items['js']['geissweb/vatvalidation-min.js']

but it return empty value, is there have a way to get that value without use foreach or for loop. Thank You

1
  • $items['js'][0]['geissweb/vatvalidation-min.js'] Commented Apr 12, 2018 at 9:27

2 Answers 2

4

Your index is '', shown by...

array(1) {
[""]=>

so you need to use...

$items['js']['']['geissweb/vatvalidation-min.js']
Sign up to request clarification or add additional context in comments.

3 Comments

it's not different in any way from my answer. [''] and [0] are the same for PHP
If I change it to 0 in my test, I get 'Undefined offset'
@Hooli - "" and 0 is not the same in php.
1

You have your variable $items['js'] as an array of arrays what your looking for without a foreach is this :

$items['js'][0]['geissweb/vatvalidation-min.js'] is not valid

after tests

 $items['js'][""]['geissweb/vatvalidation-min.js'] is valid.

1 Comment

yes i notices another issue i come back to you in five after tests :)

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.