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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:10:35+00:00 2026-06-03T03:10:35+00:00

<?php $bigArray = array( array(‘John’,’2012-03-29′,1), array(‘Doe’,’2012-03-30′,1), array(‘John’,’2012-03-31′,2), array(‘Doe’,’2012-03-31′,5), array(‘Tom’,’2012-03-31′,5), array(‘John’,’2012-04-02′,5), array(‘John’,’2012-04-02′,21), array(‘John’,’2012-03-07′,21) ); $cache

  • 0
<?php
$bigArray = array(
    array('John','2012-03-29',1),
    array('Doe','2012-03-30',1),
    array('John','2012-03-31',2),
    array('Doe','2012-03-31',5),
    array('Tom','2012-03-31',5),
    array('John','2012-04-02',5),
    array('John','2012-04-02',21),
    array('John','2012-03-07',21)
);

$cache = array();
foreach ($bigArray as $v) {
    if (isset($cache[$v[1]])) {
        if ($cache[$v[1][1]] == $v[2]) {
            echo "Equal";
            $cache[$v[1]] = array($v[0].','.$cache[$v[1]][0], $v[2]);//append user to same value
        }
        else if ($cache[$v[1][1]] < $v[2]) {
            echo "Replacing value! ".$cache[$v[1]][0]. " to " .$v[0]."<br/>";
            $cache[$v[1]] = array($v[0], $v[2]);
        }
    } else {
        $cache[$v[1]] = array($v[0], $v[2]);
    }
}

print_r($cache);
?>

This script finds the highest value for a particular date and saves it to a new array $cache

However when checking if the highest value is equal on the same date, it returns false?

array(
    array('Doe','2012-03-31',5),
    array('Tom','2012-03-31',5),
)

The above in the array is what is confusing me. Shouldn’t it be counted as a match?

The output:

Replacing value! John to Doe
Replacing value! Doe to Tom
Replacing value! John to John
Array
(
    [2012-03-29] => Array
    (
        [0] => John
        [1] => 1
    )
    [2012-03-30] => Array
        (
        [0] => Doe
        [1] => 1
    )
    [2012-03-31] => Array
    (
        [0] => Tom
        [1] => 5
    )
    [2012-04-02] => Array
    (
        [0] => John
        [1] => 21
    )
    [2012-03-07] => Array
    (
        [0] => John
        [1] => 21
    )
)
  • 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-03T03:10:36+00:00Added an answer on June 3, 2026 at 3:10 am

    Without going into too much detail, $v[1][1] seems to be quite nonsensical to me. It refers to the second character of the date string in your original array. You probably mean:

    $cache[$v[1]][1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

php> $a = array(a=>1,b=>0,c=>1,d=>1,e=>0); php> $b = array(); php> foreach ($a as $k =>$v){
PHP script $count = 0; foreach ($_FILES['filesToUpload'] as $file) { //upload process echo $file[$count]['tmp_name'].',';
PHP Array logic re-factor I'm trying to re-factor my code... This is PHP ...
I have the following array or arrays: $bigArray = array( array( id = 3,
PHP's explode function returns an array of strings split on some provided substring. It
Okay, in PHP I have a big array of items stored in a file.
PHP Code <?php $content = check1\r\ncheck2\r\ncheck3\r\nend... $order = array(\r\n); $replace = \n; $content= str_replace(
PHP code: foreach( ) { if() { $title = $title . $sub['TITLE'].<br />; }
PHP's array_search() does this: Searches the array for a given value and returns the
PHP functions such as 'array_map' take a callback, which can be a simple function

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.