Jump to content

Will this work with in_array()???


cooldude832

Recommended Posts

I have an array in my session variable that is like

$_SESSION['recent_items'][0]['ItemNumber'] = 1;

$_SESSION['recent_items'][1]['ItemNumber'] = 2;

$_SESSION['recent_items'][2]['ItemNumber'] = 3;

and I want to make sure somethign isn't already in the array with that name so if I say

<?Php
$Item_num = 2;
if(in_array($item_num,$_SESSION['recent_items'])){
echo "yes";
}
?>

should it echo yes???

Link to comment
https://forums.phpfreaks.com/topic/80723-will-this-work-with-in_array/
Share on other sites

It works, if your array is structured correctly (tested) -

 

<?php
session_start();

   $_SESSION['recent_items']['ItemNumber'][0] = 1;
   $_SESSION['recent_items']['ItemNumber'][1] = 2;
   $_SESSION['recent_items']['ItemNumber'][2] = 3;

$item_num = 2;
if(in_array($item_num,$_SESSION['recent_items']['ItemNumber'])){
echo "yes";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.