0
         $breakfast = array(
                               'rest_id' => $rest_id  ,
                               'type' => 'Breakfast' ,
                               'value' => $bprice  
                                );



            $lunch = array(
                               'rest_id' => $rest_id  ,
                               'type' => 'Facilities' ,
                               'value' => $lprice  
                                );


            $dinner = array(
                               'rest_id' => $rest_id  ,
                               'type' => 'Facilities' ,
                               'value' => $dprice  
                                );

            $data = $breakfast . $lunch . $dinner;

Is the way i created the array $data correct? If yes... now how do i get the array breakfast inside it, if i want to pass it to one function?

I want to do something like this:

$this->db->insert_breakfast($breakfast);

So how do i get breakfast array out of $data now?

2 Answers 2

4

If you want $breakfast, $lunch and $dinner to make a multi-dimensional array in $data, you will need to replace your assignment with the following.

$data = array('breakfast' => $breakfast, 'lunch' => $lunch, 'dinner' => $dinner);

Then you can access any of them like $data['breakfast']['value'].

I didn't quite understand the DB part. Comment back and I'd be glad to help.

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

3 Comments

re: DB; I think it might be CodeIgniter.
Ahh, not familiar with that. I guess I should be, someone down voted me for that earlier ;)
Heh. Yeah, shame on you for not knowing the intricacies of all available frameworks! And to top it off, trying to be helpful?!? Pfft ;)
3

The correct is

$data = array($breakfast, $lunch, $dinner);

The . operator means string concatenation. You can access $breakfast with $data[0], since it's the first member. You can also use associative arrays; see @Jason's answer.

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.