I’m trying to get the last item in an array, when being iterated to output something different to a string.
if (count($this->condition) > 1) {
$i=0;
while ($i < count($this->condition)){
if ($i == (count($this->condition) -1)) {
foreach ($this->condition as $key => $value){
$query .= $value['columns']." = ".$value['value'];
}
} else {
foreach ($this->condition as $key => $value){
$query .= $value['columns']." = ".$value['value']." AND ";
$i++;
}
}
}
} else {
foreach ($this->condition as $key => $value){
$query .= $value['columns']." = ".$value['value'];
}
}
However, it keeps adding the AND, meaning that $i == (count($this->condition)) is never true.
How do I resolve this?
I’ve fixed it.