I am a noob programmer so sorry in advance, but I have a problem with deleting a value out of my array.
Here I foreach my session wich is an array if multiple values are added, I check if it's an array if it is I loop trough it and echo it. I made a delete link that makes a get id(key).
foreach ($session->get('results') as $num => $value) {
if (!is_array($value)) {
echo $value . '<br>';
} else {
$av = count($value);
for ($a = 0; $a < $av; $a++)
echo $value[$a] . '<a href="export.php?key='. $num .'">verwijder</a><br>';
}
When the link is clicked it makes a get id, I check if get id is set. now I want to unset the value which has the same $key as the get id.
if (isset($_GET['key'])) {
if (is_array($value)) {
unset($value[$_GET['key']]);
}
}
At this moment the get id gets created but it doesn't unset the value with the same key. Has someone an answer to this, or an other way to do this?
$session->get('results') as $num => $value
$num
is your key of the element in $session->get('results')
your link -> <a href="export.php?key='. $num .'
if you want to delete the value with this key unset($session->get('results')[$_GET['key']])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.