Answer the question
In order to leave comments, you need to log in
How to know if an array key is the last one?
Hello!
There is this code:
class Handler {
public static function go_to($url, $parametrs = NULL)
{
if (isset($parametrs))
{
foreach ($parametrs as $key => $value)
{
if (count($parametrs) > 1)
{
$params .= $key.'='.$value.'&';
}
else
{
$params = $key.'='.$value;
}
}
}
if (isset($parametrs))
{
return header('Location: /'.$url.'?'.$params.'');
exit();
}
else
{
return header('Location: /'.$url.'');
exit();
}
}
}
<?php
Handler::go_to('index', array('succcess' => '20', 'r' => '29312'));
?>
Answer the question
In order to leave comments, you need to log in
With the end() function
if (count($parametrs) > 1){
if(end($parametrs) === $value)
$params .= $key.'='.$value;
else
$params .= $key.'='.$value.'&';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question