Skip to content
Advertisement

Target index of array

I’m trying to target the index of my array. For some reason my array turns out really weird.

JavaScript

Now I get the results I need. But I need the name of each index too.

Results:

var export – $name:

JavaScript

var_export – $mednames:

JavaScript

var_export – $cnt:

JavaScript

var_export – $c:

JavaScript

Now the problem here is that I need to have the name of each medicine in the $c variable/array, because I need the name of the medicine to get more information from the api. But the problem is I’m only getting the count for it. Is there a workaround for this? This is really bugging me. I’ve been stuck on this for hours.

Advertisement

Answer

You need to access the key in the second foreach:

JavaScript

You can test this in php Sandbox, that this is in fact correct behaviour:

https://sandbox.onlinephpfunctions.com/

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement