0

Have been off the PHP scene for a long time. I now need to adjust a Wordpress plugin and basically have the following :

    $count_of_stuff=10
    for ($i=0; $i<$count_of_stuff; $i++) {
    $wpdb->insert($wpdb->prefix."numbers_table", array(
   "id" => $id,
        "num" => $number));
        $number++;
        }

Instead of using $number++ ( incrementing by 1 ) I need to pull from a list of numbers that arent necessarily sequential. ( 123,345,346,457,458,459 ). ( I will store these in a table )

Any thoughts/assistance? I am looking at the range option currently so may find an answer...

Thank you .

2
  • you could use "num" => $number[$i] referencing an array $number = [123,345,346,457,458,459, ...]; defined before the loop (and drop the line with $number++) Commented Nov 10, 2020 at 22:02
  • Thank you will try when back at desk Commented Nov 10, 2020 at 22:13

1 Answer 1

1

Can you try

 $custom_array=array(123,345,346,457,458,459);  
 $count_of_stuff=6;
 for($i=0; $i<$count_of_stuff; $i++) 
 {
 $number=$custom_array[$i];
 $wpdb->insert($wpdb->prefix."numbers_table", array("id" => $id,"num" => $number));
 
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.