この配列からデータを取得するための最良の選択肢は何ですか?
array(4) {
[0]=> array(10) {
["id"]=> string(3) "158"
["name"]=> string(8) "Tractors"
["parent_id"]=> string(1) "0"
["image_id"]=> string(2) "37"
["blurb"]=> string(17) "Agrilife Tractors"
["brand_name"]=> string(4) "SAME"
["brand_id"]=> string(1) "2"
["cat_id"]=> string(1) "1"
["sorder"]=> string(1) "0"
["state"]=> string(1) "1"
}
[1]=> array(10) {
["id"]=> string(3) "159"
["name"]=> string(8) "Ride Ons"
["parent_id"]=> string(1) "0"
["image_id"]=> string(2) "74"
["blurb"]=> string(0) ""
["brand_name"]=> string(4) "SAME"
["brand_id"]=> string(1) "2"
["cat_id"]=> string(1) "2"
["sorder"]=> string(1) "1"
["state"]=> string(1) "1"
}
[2]=> array(10) {
["id"]=> string(3) "160"
["name"]=> string(9) "Machinery"
["parent_id"]=> string(1) "0"
["image_id"]=> string(2) "14"
["blurb"]=> string(0) ""
["brand_name"]=> string(4) "SAME"
["brand_id"]=> string(1) "2"
["cat_id"]=> string(1) "3"
["sorder"]=> string(1) "2"
["state"]=> string(1) "1"
}
[3]=> array(10) {
["id"]=> string(3) "161"
["name"]=> string(17) "Outdoor Equipment"
["parent_id"]=> string(1) "0"
["image_id"]=> string(3) "114"
["blurb"]=> NULL
["brand_name"]=> string(4) "SAME"
["brand_id"]=> string(1) "2"
["cat_id"]=> string(1) "5"
["sorder"]=> string(1) "3"
["state"]=> string(1) "1"
}
}
Tractors
私の HTML は次のようにforeach
なります。必要なときに必要な場所でエコーできるように、関連するすべてのデータを取得しようとしています。
HTML:
foreach($assoc_categories as $assoc_cat)
{
// Page load - does assoc exist?
$checked_state = "";
$does_assoc_exist = $this->Ps_products_model->brand_specific_cat_assoc_exist($brand_id, $assoc_cat['id']);
if($does_assoc_exist == "1")
{
$checked_state = " checked='checked'";
}
?>
<div>
<input type="checkbox" name="product_category" class="product_category_selector" id="product_category_<?php echo $assoc_cat['id']; ?>" data-id="<?php echo $assoc_cat['id']; ?>" <?php echo $checked_state; ?> /> <?php echo $assoc_cat['name']; ?>
</div>
<input class="order" type="input" />
<?php
}
?>