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 8373695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:44:39+00:00 2026-06-09T14:44:39+00:00

I came to situation when I need to check if array2 has some value

  • 0

I came to situation when I need to check if array2 has some value (randomly generated) from array1. So far I though of

redo : $id=mt_rand(0,count(array1));
foreach($array2 as $arr)
{
    if($arr[0]==$id) goto redo;
}
//Some actions if randomly generated value from array1 wasn't found in array2

But I’d really prefer not to use goto. I’m pretty sure there is some simple solution to do this without goto but I just can’t think of it D:

  • 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-06-09T14:44:41+00:00Added an answer on June 9, 2026 at 2:44 pm

    You can use a numeric parameter with continue:
    http://www.php.net/manual/en/control-structures.continue.php

    while(true){
      $id = mt_rand(0,count(array1);
    
      foreach( $array2 as $arr )
        // restart the outer while loop if $id found
        if( $arr[0] == $id ) continue 2;
    
      // $id not found in array, leave the while loop ...
      break;
    };
    
    // ... and do the action
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this situation where I need to get some data from a webpage
I have came across a situation where I need to merge values from two
I came across this situation while migrating our DB from Foxpro to SQL. Below
I have a situation where I need to write some unit tests for some
In my code, I have a situation where I need to copy data from
I'm pretty capable when coding PHP though I just came across a situation where
In attempts of 100% code coverage, I came across a situation where I need
I recently came across a situation where I had to use XPath as part
I came across with these situation while building a class diagram for a system,
I came across with a curious situation when using jamod to write to modbus.

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.