Jump to content

Getting array data in variable


Go to solution Solved by mac_gyver,

Recommended Posts

I'm trying to include an array inside of a different array, but having trouble reaching the data.

$ingredients = ["sugar", "flour", "water"];
$spec_recipe = ["apple", "cinnamon", $ingredients];

echo $spec_recipe[2];
RESULT:  Array
echo $spec_recipe[2][0];
RESULT:  A  (assuming first letter of Array)

How do I move this info correctly so that it's accessible?

Edited by phppup
Forgot item
Link to comment
https://forums.phpfreaks.com/topic/326661-getting-array-data-in-variable/
Share on other sites

@gw1500se No luck.

In not sure if it matters that this variable is stuck into a sub array.

This started out working well with single words or phrases. But when I incorporated an array to provide those words and phrases, it went bonkers.

I felt that the array structure was getting cluttered and that variables would help organize it. Was I wrong?

@mac_gyver Save as my initial info in this question.

Both direct access efforts and print_r:

[6] => Array

The data is not getting pulled by the variable, yet it knows there's an array present.

Not sure if exact version, but current.

Edited by phppup
Forgot item

** Recent development **

I modified my approach and got a response

//At first

$ingredients = ["sugar", "flour", "water"];
$spec_recipe = ["apple", "cinnamon", $ingredients];

echo $spec_recipe[2];
RESULT:  Array
echo $spec_recipe[2][0];
RESULT:  A  (assuming first letter of Array)

Now I altered the variable to specify an element

$ingredients = ["sugar", "flour", "water"];
$spec_recipe = ["apple", "cinnamon", $ingredients[0] ];
echo $spec_recipe[2];
RESULT:  sugar

I suppose this is something, but I want the array to become available through this variable so that I can address the full array contents.

What am I missing?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.