PHP foreach loop key value

0 votes

Running this DB call will provide me with a multidimensional array. I'm attempting to retrieve each key, but it always returns as a blank page or an array.

$root_array = array();
$sites = $this->sites($member_id);
foreach ($sites as $site){
    $records = $this->db->select('p.name as place_name, p.id as place_id,p.active as place_status')
                ->from('places p')
                ->join('members_permissions pm','pm.sites_id = p.sites_id and pm.members_id ='.$member_id)
                ->where('p.active', 0)
                ->get();

    $places = $records->result_array();
    $places['name'] = $site['name'];
    foreach($places as $place){
       $root_array[$site['name']][] = $place;
    }

}
return $root_array;

My PHP that loops through:

<?php foreach($places as $site): ?>
    <h5><?=key($site)?></h5>
        <?php foreach($site as $place): ?>
            <h6><?=$place['place_name']?></h6>
        <?php endforeach?>

<?php endforeach ?>

Additionally, the result of a test I ran that only output the array is [Philadelphia], which is what I'm trying to render.

[Philadelphia] => Array
        (
            [0] => Array
                (
                    [place_name] => XYX
                    [place_id] => 103200
                    [place_status] => 0
                )

            [1] => Array
                (
                [place_name] => YYYY
                [place_id] => 232323
                [place_status] => 0
            )

Can someone please help me with this?

Aug 1 in PHP by Kithuzzz
• 4,480 points
12 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How to delete element by value in array (not key) using php?

Hello @kartik, Using array_search() and unset, try the following: if (($key = ...READ MORE

answered Sep 16, 2020 in PHP by Niroj
• 82,740 points
221 views
0 votes
0 answers

PHP - Get key name of array value

I have an array of the following: function ...READ MORE

Jul 22 in PHP by narikkadan
• 11,280 points
7 views
0 votes
0 answers

How to sort an array of associative arrays by value of a given key in PHP?

Given this array: $inventory = array( ...READ MORE

Jul 24 in PHP by Kithuzzz
• 4,480 points
20 views
0 votes
0 answers

How to push both value and key into PHP array

Take a look at this code: $GET = ...READ MORE

Jul 25 in PHP by Kithuzzz
• 4,480 points
14 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,740 points
1,492 views
0 votes
1 answer

Invalid argument supplied for foreach() on line 25. Error in my php and mysql

Hello @viven , This should be a simple fix ...READ MORE

answered Aug 4, 2020 in PHP by Niroj
• 82,740 points
1,610 views
0 votes
0 answers

Invalid argument supplied for foreach()

To handle data that can be either ...READ MORE

Apr 28 in Other DevOps Questions by Kichu
• 19,040 points
37 views
0 votes
0 answers

How to access mysql result set data with a foreach loop

I'm working on a PHP application that ...READ MORE

Jul 29 in PHP by Kithuzzz
• 4,480 points
41 views
0 votes
0 answers

How does PHP 'foreach' actually work?

Let me start by stating that I ...READ MORE

Aug 7 in PHP by Kithuzzz
• 4,480 points
9 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
544 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP