0
I have the following arrays:
$arrTag = "Array ( [0] => stdClass Object ( [id] => 1 [id_pacote] => 7 [id_fornecedor] => [nome] => Salgados - 100 Un [valor_compra] => 100 [valor_venda] => 150 [descricao] => Pacote de Salgados com 100 unidades [created_at] => 2016-11-03 18:00:55 [updated_at] => ) [1] => stdClass Object ( [id] => 2 [id_pacote] => 7 [id_fornecedor] => [nome] => Doces - 100 Un [valor_compra] => 50 [valor_venda] => 114 [descricao] => Pacote com 100 unidades de doces [created_at] => 2016-11-03 18:01:31 [updated_at] => ) [2] => stdClass Object ( [id] => 3 [id_pacote] => 7 [id_fornecedor] => [nome] => Refrigerante - 10 un [valor_compra] => 50 [valor_venda] => 85 [descricao] => Pacote com 10 unidades de refrigerantes [created_at] => 2016-11-03 18:02:04 [updated_at] => ) )";
$arrBanco = "Array ( [0] => stdClass Object ( [valor_venda] => 150 [id] => 1 ) [1] => stdClass Object ( [valor_venda] => 85 [id] => 3 ) )";
I need to compare if the id inside arrTag equals the id inside arrBanco and put echo "checked";
It summarizes in a list of the database, where I have a list of items (pacotes_items) and will be marked the items that have already been purchased (pacotes_itens_purchased).
HTML TO BE INSERTED CHECKED.
Within the input type="checkbox"
<table class="table table-bordered">
<tr>
<th width="50" class="text-center">#</th>
<th>Item do Pacote</th>
<th>Valor</th>
<th width="50" class="text-center"></th>
</tr>
<?php
if(count($dados->detalhes_pacote)>0){
foreach($dados->detalhes_pacote as $valor_pacote){
?>
<tr>
<td width="50" class="text-center"><?php echo $valor_pacote->id; ?></td>
<td><?php echo $valor_pacote->nome; ?></td>
<td>R$ <?php echo number_format($valor_pacote->valor_venda, "2", ",", "."); ?></td>
<td width="50" class="text-center"><input type="checkbox" name="itens[]" id="itens[]" class="checados" data-id="<?php echo $valor_pacote->id; ?>" value="<?php echo number_format($valor_pacote->valor_venda, "2", ",", "."); ?>|<?php echo $valor_pacote->id; ?>"></td>
</tr>
<?php
}
} else {
?>
<tr>
<td colspan="4" class="text-center">Nenhum item foi adicionado a este pacote.</td>
</tr>
<?php } ?>
</table>
where are these variables? arrtag, arrbanco...
– Daniel Omine
They are in the above question... I just don’t know how to check inside the arrays, if the id of one is equal to the id of the other
– Sr. André Baill
within the larger code, where both variables are?
– Daniel Omine
What do you want with this array representing within a
string
? You’re thinking of using theeval
?– Wallace Maxters
Put the code that has the arrays in the question. With those two strings you can’t know what you want. You need to put the real arrays, not the visual representation of them..
– Bacco