Clint
Clint

Reputation: 463

Trying to create associative array but keep getting numeric

I am trying to create an associate array like this

while($row = $result1->fetch_assoc()) {

        $user = $row['first_name'] ."_" . $row['last_name'];
        $userholder[$user] = $row['choice'];
        $event = $row['event_name'] . "_" . $row['event_location'] . "_" . $row['even_date'];
        $consolidateEvents[$event] = $userholder;
    }

but my $consolidateEvents array is numeric. I cannot see what I am doing wrong. Why am I not getting $event as the key for my array?

Upvotes: 2

Views: 31

Answers (1)

Rahul
Rahul

Reputation: 18557

Try this code to correct your output,

function custom_function($input_array){
    $output_array = array();
    foreach ($input_array as $key => $value) {
        foreach ($v as $k => $v) {
            $output_array[$key][$k] = $v;
        }
    }
    return $output_array;
}

Give it a try, this will work

Upvotes: 1

Related Questions