Is this a good piece of code or will it not work or is not efficient?
The user enters data into the database and $id is the unique id for the record.
The user has the option of entering multiple records into the table. I want to hold all of the IDs of the records that the user has entered into the database into a session.
<?php
$array = $_SESSION['graphics'];
$id = mysql_insert_id();
if(!is_array($array))
{
$array = array('$id');
}else{
$mode = end($array);
foreach($array as $key=>$value)
{
if($value == $mode)
{
$last_key = $value;
$new_key = $last_key + 1;
}
}
$array[$new_key] = $id;
}
?>