-1

I'm working on a multi-dimensional array using for loop, I checked the data and all of them are showing.

My problem is I always get this error Notice : Undefined offset and it points to this line for ($x=0; $x < $result[$i][$x]; $x++) {.

SAMPLE CODE

for ($i = 0; $i < count($result); $i++)
  {
  for ($x = 0; $x < $result[$i][$x]; $x++)
    {
    // code...
    $data = $result[$i][$x];
    echo '
              <div class="col-6">
               <div class="res-cont">
                <div class="count">' . ($x + 1) . '</div>
                <h4>' . $data['title'] . '</h4>
                <p>' . $data['meta'] . '</p>
                <span>' . $data['url'] . '</span>
               </div>
              </div>
         ';
    }
  }
yivi
  • 42,438
  • 18
  • 116
  • 138
user123
  • 435
  • 1
  • 6
  • 23
  • Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – yivi Jan 15 '19 at 14:39

1 Answers1

1

Please replace the line with this for ($x = 0; $x < count($result[$i]); $x++) and keep it in mind that notice is not really an error!

mahdi azarm
  • 340
  • 2
  • 7
  • 18