Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 735067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:26:46+00:00 2026-05-14T07:26:46+00:00

I have an array, which holds values like this: $items_pool = Array ( [0]

  • 0

I have an array, which holds values like this:

$items_pool = Array ( 
[0] => Array ( [id] => 1 [quantity] => 1 ) 
[1] => Array ( [id] => 2 [quantity] => 1 ) 
[2] => Array ( [id] => 72 [quantity] => 6 ) 
[3] => Array ( [id] => 4 [quantity] => 1 )
[4] => Array ( [id] => 5 [quantity] => 1 ) 
[5] => Array ( [id] => 7 [quantity] => 1 ) 
[6] => Array ( [id] => 8 [quantity] => 1 ) 
[7] => Array ( [id] => 9 [quantity] => 1 ) 
[8] => Array ( [id] => 19 [quantity] => 1 ) 
[9] => Array ( [id] => 20 [quantity] => 1 ) 
[10] => Array ( [id] => 22 [quantity] => 1 ) 
[11] => Array ( [id] => 29 [quantity] => 0 ) 
) 

Next, I have a form that I am trying to populate. It loops through the item database, prints out all the possible items, and checks the ones that are already present in $items_pool.

<?php foreach ($items['items_poolpackage']->result() as $item): ?>

<input type="checkbox" name="measure[<?=$item->id?>][checkmark]" value="<?=$item->id?>"> 

<?php endforeach; ?>

I know what logically I’m trying to accomplish here, but I can’t figure out the programming.

What I’m looking for, written loosely is something like this (not real code):

<input type="checkbox" name="measure[<?=$item->id?>][checkmark]" value="<?=$item->id?>" <?php if ($items_pool['$item->id']) { echo "SELECTED"; } else { }?>>

Specifically this conditional loop through the array, through all the key values (the ID) and if there’s a match, the checkbox is selected.

<?php if ($items_pool['$item->id']) { echo "SELECTED"; } else { }?>

I understand from a loop structured like this that it may mean a lot of ‘extra’ processing.

TL;DR – I need to loop within the array, check for the key ‘id’, then print a string.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:26:46+00:00Added an answer on May 14, 2026 at 7:26 am

    If I understand correctly, you need something like this?

    array_walk($items_pool, create_function('$array', 'global $item; if( in_array($item->id, $array) ) { echo "checked=\"checked\""; }'));
    

    Conside this though, if you stored your products in a single dimensional array (presuming the ids will always be unique

    $items_pool = array(id, quantity)
    

    You will not end up with having duplicated entries of products and can incremement/decrement the quantity easier.

    $items_pool[id]++; /* or */ $items_pool[id] = $items_pool[id] + 2;
    

    Both techniques should work if the id exists in the array or not.

    If you are hoping to store other attritubes in this array other than quantity, you can

    $items_pool = array(id=>array(quantity=>3, colour=>"red"));    
    $items_pool[id][quantity]--;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 366k
  • Answers 366k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I figured it out... I had to declare them as… May 14, 2026 at 4:43 pm
  • Editorial Team
    Editorial Team added an answer Display: It sounds like your model isn't returning sensible content… May 14, 2026 at 4:43 pm
  • Editorial Team
    Editorial Team added an answer You need to escape the $(...) with a backslash to… May 14, 2026 at 4:43 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.