0

I would like to do that :

$product[] = Array (
                            "article_title" => valeures,
                            "article_id" => ,
                            "article_value" => ,
                            "article_price" =>
                            "article_picture1" => ,
                            "article_picture2" => ,
                            "article_picture3" => ,
                            "article_picture4" => ,
                            "article_friends[]" => array ( "name" => ,
                                                    ),

                        );

But I know it won't work, I've been looking for hours on the net and on php.net, but I don't know how to do. What I want to do, is getting a product[] array that can handle product[1]; product [2] ... and inside it, I got the same process : the "article_firends[]" will be autoincremented to do something like that :

In product[1] : artcile_friends[1][name] = John ; article_freidns[2][name] = Nina ... and so on with product[2] ...

This has been implementedin a foreach loop so it Should manage the keys automatically .. How can I build it ?

Many Thanks, Miles

2
  • So....was there a question somewhere in there? Commented Jan 25, 2012 at 16:15
  • well .. yeah, I'm looking for the right way to write it :) Commented Jan 25, 2012 at 16:25

2 Answers 2

2
"article_friends[]" => array ( "name" => ,

doesn't create a new article_friends sub array. It creates a key in the parent $product array whose name happens to be article_friends[].

Remove the quotes from around the key, so you end up with

article_friends[] => array ( "name" => , ...
Sign up to request clarification or add additional context in comments.

1 Comment

I'm trying to test this.. Are you saying $products[] = array( article_friends[] => array ("name" => "test") ); should work?
0

This totally does work.

You're getting an error because of valeures, either this is a variable, than add a '$' or it's a string, than add quotes. "article_friends[]" => array ( "name" => , is wrong too, you have to add a value after "name".

The trailing comma in the 'article_friends[]' line should be omitted to.

2 Comments

Thanks, When I put Valeures I meant Values, like the value I want it to take, I know I have to put some variables in there, but will the article_firends[] will autoincrement each time I update the $product array to put another article_friends[] ?
no, "article_friends[]" is a string, therefore it acts like a normal key in your array. assuming you want to store a list of friends there, you can do something like this: ...."article_friends" => array ( "name1", "name2", "name3" )...

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.