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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:20:36+00:00 2026-06-17T17:20:36+00:00

I have a snippet of PHP code like this: while($attempts < $cycles) { foreach($player_array

  • 0

I have a snippet of PHP code like this:

  while($attempts < $cycles) {

        foreach($player_array as $player) {
                if(isset($player['results']) && $player['results'] == 1) {
                        $player['results'] = player_search($f, $s, $t);
                }
        }
}

The idea is for each item in the array it calls a search function. If the search has nothing, it returns false, which SHOULD stop it from calling the search for the rest of the remaining cycles by changing the value of ‘results’.

I’m assuming that setting $player['results'] as false does not actually set the correct variable for when it pulls it in on the next iteration.

How should i change my code to get this working properly?

EDIT:

Can I make clear that if a search in a function returns no results I do not want that function to be called again, I DO however want the same function to be used for the other searches if they still have results. Obviously once all player searches have no result i would ideally like to break the while loop too.

  • 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-17T17:20:37+00:00Added an answer on June 17, 2026 at 5:20 pm

    I’m not sure whats going on with $attempts and $cycles since they dont seem to be changed from within the loop but if you really want to change the value in $player contained in $player_array you should do

    foreach($player_array as &$player) {
        if(!isset($player['results'])) {
            $player['results'] = player_search($f, $s, $t);
        }
    }
    

    notice I changed $player to &$player so that it becomes a reference instead of a copy

    I also changed your isset so that it only does a search if the results are not stored in results already

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this PHP snippet: <?php $colors = array('red','green','blue'); foreach ($colors as &$item) {
I have this code snippet in an email layout: <div> <?php echo $this->Html->image('Layouts/default/Logo.png', array(
I have PHP snippets like this ( snippet.php ): <?php $some_param = some_function(); ?>
have a php code like this,going to convert it in to C#. function isValid($n){
I have a php code snippet like below : function is_ancestor_of( $page_name = null,
Right now my CSS files look like this: Then I have a php snippet
I have this snippet of code: var ShopLogicOptions = {}; ShopLogicOptions.params = {orderId: '
I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t =
I have URLs like below that need to be recognized by the PHP code.
I have a mysql code like this... INSERT INTO `product` (`product_id`, `model`, `sku`) VALUES

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.