I'm calling this php type inside cakephp which is "in_array". Basically I'm checking whether both fields are available inside the array. The problem is that by this method it should result in outputting only one statement by checking if the fields are in the array. The result is like skipping the array check and outputting both statements which is incorrect.
This is my call in the View.ctp,
foreach($types as $type)
{
if(in_array(array($carId, $type->type_id), $types))
{
echo $this->Html->link(
'Remove',
['controller' => 'cars', 'action' => 'removeType'],
['class' => 'btn btn-success']
);
}else
{
echo $this->Html->link(
'Add',
['controller' => 'cars', 'action' => 'addType'],
['class' => 'btn btn-success']
);
}
This is how I'm calling my database:
$typesTable = TableRegistry::getTableLocator()->get("Types");
$types = $typesTable->find('all')->toArray();
$this->set('types', $types);
The output result should be a button Remove if $carId is equal to $typesId in the database, if not equal to Add button should be displayed.