0

I have two arrays. The first one is created by making chunks of the array $properties.

$array1 = array_chunk($properties,10000,true);

It looks like this:

array(4) {
  [0]=>
  array(10000) {
    ["12345"]=>
    array(5) {
      ["dateTime"]=>
      string(19) "2016-10-12 19:46:25"
      ["fileName"]=>
      string(46) "monkey.jpg"
      ["path"]=>
      string(149) "Volumes/animals/monkey.jpg"
      ["size"]=>
      string(7) "2650752"
    }
    ["678790"]=>
    array(5) {
      ["dateTime"]=>
      string(19) "2016-10-12 14:39:43"
      ["fileName"]=>
      string(45) "elephant.jpg"
      ["path"]=>
      string(171) "Volumes/animals/elephant.jpg"
      ["size"]=>
      string(7) "2306688"
    }

... and so on.

The other one is created from the database:

  $countResult = "SELECT COUNT(*) AS `count` FROM files"; 
  $q = $pdo->prepare($countResult);
  $q->execute();
  $row = $q->fetch(PDO::FETCH_ASSOC);
  $totalCount = $row['count'];
  $chunkSize = 10000;
  $from      = 0;

while($from < $totalCount)
{
   $sql = 'SELECT id, dateTime, fileName, path, size FROM files LIMIT ' . $from . ', ' . $chunkSize . ';'; 
   $q = $pdo->prepare($sql);
   $q->execute();
   $rows = $q->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_UNIQUE | PDO::FETCH_ASSOC);

   echo "<pre>";
   var_dump($rows);
   echo "</pre>";

   $from += $chunkSize;
}

The result of var_dump($rows) is this:

array(10000) {
  ["12345"]=>
  array(5) {
         ["dateTime"]=>
          string(19) "2016-10-12 19:46:25"
          ["fileName"]=>
          string(46) "monkey.jpg"
          ["path"]=>
          string(149) "Volumes/animals/monkey.jpg"
          ["size"]=>
          string(7) "2650752"
  }
  ["678790"]=>
  array(5) {
      ["dateTime"]=>
          string(19) "2016-10-12 14:39:43"
          ["fileName"]=>
          string(45) "elephant.jpg"
          ["path"]=>
          string(171) "Volumes/animals/elephant.jpg"
          ["size"]=>
          string(7) "2306688"
  }

and so on...

array(10000) {
  ["23424"]=>
  array(5) {
         ["dateTime"]=>
          string(19) "2016-10-12 14:46:25"
          ["fileName"]=>
          string(46) "rabbit.jpg"
          ["path"]=>
          string(149) "Volumes/animals/rabbit.jpg"
          ["size"]=>
          string(7) "2655752"
  }
  ["163452"]=>
  array(5) {
      ["dateTime"]=>
          string(19) "2016-10-12 12:39:43"
          ["fileName"]=>
          string(45) "snake.jpg"
          ["path"]=>
          string(171) "Volumes/animals/snake.jpg"
          ["size"]=>
          string(7) "2406688"
  }


and so on...

So $array1 is a splitted array, that somehow looks like as if it is still one array that contains 4 arrays... (I do not really understand this), but however: I need to create a second array ($array2) from the mysql database input that will look exactly like $array1 and I do not know how to achieve is. The purpose is that I want to compare $array1 and $array2 the check if they are matching.

1
  • 1
    An array is just a container. So it can contain arrays. (MultiDimensional Arrays). It's easy to make the 2nd section in an array just put $super_rows[] = $rows into your look and var dump the $super_rows but comparing them is lots of fun Commented May 16, 2018 at 17:32

1 Answer 1

1

Create the array before the while, then push the data from database:

//create the array here
$rows = [];
while($from < $totalCount)
{
   $sql = 'SELECT id, dateTime, fileName, path, size FROM files LIMIT ' . $from . ', ' . $chunkSize . ';'; 
   $q = $pdo->prepare($sql);
   $q->execute();
   //HERE $rows[]
   $rows[] = $q->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_UNIQUE | PDO::FETCH_ASSOC);

   echo "<pre>";
   var_dump($rows);
   echo "</pre>";

   $from += $chunkSize;
}

Then compare the way you want, the array $rows with $array1

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.