Jump to content

in_array help!


Kelset

Recommended Posts

Ok i'll just post my code and see what you guys think, here is what I'm trying to do frist.

The user log in to the images display page, image for that user is dispalyed and each image has a checkbox with the name
of five. They select the images they would like to keep they hit a form button called "Add Image". This code fires when
that button is hit, there is some paging of images and stuff but this is all I think needs to be shown.

[code]
//Convert session array into easy to use var
$sess_five = $_SESSION['five'];

//Store checkbox array in var for easy use
$five = $_POST['five']; //This will be an array from checkboxes

//check to see if any photos have been checked
//Get number of checkboxs checked
if (!empty($five)) {
    //count how many images in each array
$five_count = count($five);
   
//loop through each array and see if the value is already stored in it
for ($i=0;$i<$five_count;$i++) {
if (in_array($five[$i], $sess_five)){
echo " YOU HAVE ONE"; // Just some testing text
}else{
//add to session var
$sess_five .= $five[$i];
}//End if
}//End for
}//End if

//Store the array back into a session
$_SESSION['five'] = $sess_five;

[/code]


any help would be great!

cheers!
Stephen
Link to comment
https://forums.phpfreaks.com/topic/26363-in_array-help/
Share on other sites

I'm sorry :(

Ok the error I'm getting is this.

Warning: in_array() [function.in-array]: Wrong datatype for second argument in G:\wamp\www\littlecreations\display.php on line 38

Line 38 is

if (in_array($five[$i], $sess_five)){

any ideas why I'm getting this error? says that it is wrong type but $sess_five is an array as far as I know. I set the
session when they login to be empty $_SESSION['five'] should it be set different way?

Thank you for you time in this for me

Cheers!
Stephen
Link to comment
https://forums.phpfreaks.com/topic/26363-in_array-help/#findComment-120557
Share on other sites

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.