Chris Chris - 3 months ago 6x
PHP Question

PHP function not seeing value of second parameter

For some odd reason my PHP is not seeing the value of the second parameter.

My code:

PHP function:

public function getVacs($key, $id = null, $deleted = null, $deleted_key = null) {

if(!$id) {
$data = $this->_db->getAll('vacatures', $key);
} elseif(!empty($deleted)) {
$data = $this->_db->getAll('vacatures', $key, $id, $deleted, $deleted_key);
} else {
$data = $this->_db->getAll('vacatures', $key, $id);

if($data->count()) {
$this->_data = $data->results();
$this->_count = $data->count();
return true;

Calling the function:

} elseif(isset($_POST['all'])) {

$vacs = $v->getVacs('delete', '0');

echo json_encode($v->data());

The problem is, the function does not see the value of

It's running the first
while it should be running the

Ray Ray

In php the string "0" evaluates to false.

This means your check if(!$id) will evaluate to true and by your logic id won't be set in $data.

If the string "0" is legitimate option, then check for null explicitly instead:


This will