0

I can not get this to work.
How do I change key [0] to [id]. In the below array ex. I want the [0] => 2 to look like [id] => 2

Array ex.:

Array
(
    [pickup] => 2014/11/10 15:15
    [tire_front] => tire_front
    [service] => 4
    [message] => 
    [user] => 1
    [0] => 2
)

My php script:

<?php
if (isset($_POST['rep_list'])) {
    //insert database connect script here 
    $workCard = $_POST['rep_list'];
    array_push($workCard, $id); 
    print_r($workCard) ."<br>"; 
}
else{
    echo("errorrrrr");
}
?> 

SOLVED

<?php
if (isset($_POST['rep_list'])) {
    //insert database connect script here 
    $workCard = $_POST['rep_list'];
    $workCard['id'] = $id;
    print_r($workCard) ."<br>"; 
}
else{
    echo("errorrrrr");
}
?>
Nomis
  • 437
  • 1
  • 4
  • 13

2 Answers2

1

You should not use array_push for this

$workCard['id'] = $id;

If it is already setted you can unset($workCard[0])

dynamic
  • 46,985
  • 55
  • 154
  • 231
1

Use this:

$workCard['id'] = $id;
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252