VAPPM
VAPPM

Reputation: 73

How to remove array index from php array?

My function is waiting response in array as in format below:

main[insert][id][insert]='some value'

I have prepared loop:

for ($i=0; $i<100; $i++) {
$data_array[] = array(
"insert" => array($data[$i]["id"] => 
array ("insert" => "some value"; }

However after I run it I have such values:

main[insert][//i value from 0 to 99][id][insert] = "some value"
main[insert][0][005][insert] = "some value"
main[insert][1][008][insert] = "some value"

Everything looks good I just don't need this loop i values, I just need values without it of such view: main[insert][id][insert]='some value'

Upvotes: 1

Views: 69

Answers (1)

oreopot
oreopot

Reputation: 3450

Try replacing your loop with the below code:

It will be great if you could provide the structure of $data

for ($i=0; $i<100; $i++) {

  $data_array[][ "insert"] = [ 
                                $data[$i]["id"] => ["insert" => "some value"]
                               ]
}

edit: From your solution in comment: @VAPPM

for ($i=0; $i<100; $i++) { 
  $current_id=$data[$i]['id']; 
  $data_array['insert'][$current_id]['insert'] = "some value"; 
}

Upvotes: 2

Related Questions