Search the Community
Showing results for tags 'in_array'.
-
Is there a better way to do this? $p = 3; $a = 3; $b = 3; $arr = [$p,$a,$b]; if (in_array(0, $arr)) { return 'Pending'; } if ((in_array(2, $arr)) && !in_array(0, $arr)) { return 'Incomplete'; } if ((in_array(1, $arr)) && !in_array(0, $arr) && !in_array(1, $arr)) { return 'Approved'; } if (in_array(3, $arr) && !in_array(0, $arr) && !in_array(1, $arr) && !in_array(2, $arr)) { return 'Declined'; }
-
In the elseif below if the $group_num is in the $dont_print I don't want add the info, what am I doing wrong $dont_print = array(0, 12); foreach ($group_array as $key => $group_num) { if (!$add_on_sql) {$add_on_sql = 'WHERE id_group = '.$group_num.'';} elseif (in_array($group_num, $dont_print, FALSE)) {$add_on_sql .= ' OR id_group = '.$group_num.'';} } Thanks
-
I can't figure out what's wrong with this. The program works, but the deduplication doesn't work. The error I get is : Warning: in_array() [function.in-array]: Wrong datatype for second argument in line 67. I bolded line 67 below, which is an if (in_array ) statement. in_array wants an array for the second argument, which I have, so don't see the problem. Any suggestions? TIA ---------------------------------------------------------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Song Organizer</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1>Song Organizer</h1> <?php // handle parameters in the URL if (isset($_GET['action'])) { if ((file_exists("SongOrganizer/songs.txt")) && (filesize("SongOrganizer/songs.txt") != 0)) { $SongArray = file("SongOrganizer/songs.txt"); // menu for Deduplication, Sort, Shuffle switch ($_GET['action']) { case 'Remove Duplicates': $SongArray = array_unique($SongArray); $SongArray = array_values($SongArray); break; case 'Sort Ascending': sort($SongArray); break; case 'Shuffle': shuffle($SongArray); break; } // end of switch statement // save the song list after it has been modified if (count($SongArray) > 0) { $NewSongs = implode($SongArray); $SongStore = fopen("SongOrganizer/songs.txt", "wb"); if ($SongStore === false) echo "There was an error updating the song file\n"; else { fwrite($SongStore, $NewSongs); fclose($SongStore); } } else unlink("SongOrganizer/songs.txt"); } } // read song file data into the $ExistingSongs array if (isset($_POST['submit'])) { $SongToAdd = stripslashes($_POST['SongName']) . "\n"; $ExistingSongs = array(); if (file_exists("SongOrganizer/songs.txt") && filesize("SongOrganizer/songs.txt") > 0) { $ExistingSongs = file("SongOrganizer/songs.txt"); } } // check to see if the song name entered is already in the song list // this is where it has a problem. if (in_array($SongToAdd, $ExistingSongs)) { echo "<p>The song you entered already exists!<br />\n"; echo "Your song was not added to the list.</p>"; } // add new song to the list file else { $SongFile = fopen("SongOrganizer/songs.txt", "ab"); if ($SongFile === false) echo "There was an error saving your message!\n"; else { fwrite($SongFile, $SongToAdd); fclose($SongFile); echo "Your song has been added to the list.\n"; } } // display the song list, or empty message if song list is empty if ((!file_exists("SongOrganizer/songs.txt")) || (filesize("SongOrganizer/songs.txt") == 0)) echo "<p>There are no songs in the list.</p>\n"; else { $SongArray = file("SongOrganizer/songs.txt"); echo "<table border=\"1\" width=\"100%\" style=\"background-color:lightgray\">\n"; foreach ($SongArray as $Song) { echo "<tr>\n"; echo "<td>" . htmlentities($Song) . "</td>"; echo "</tr>\n"; } echo "</table>"; } ?> <!-- Show hyperlinks for the three functions in the switch statement (Sort, Remove Dups, Shuffle) --> <p> <a href="SongOrganizer.php?action=Sort%20Ascending">SortSong List</a><br /> <a href="SongOrganizer.php?action=Remove%20Duplicates">Remove Duplicate Songs</a><br /> <a href="SongOrganizer.php?action=Shuffle">Shuffle Song List</a><br /> </p> <!-- web form for entering new song names into the song list --> <form action="SongOrganizer.php" method="post"> <p>Add a New Song</p> <p>Song Name: <input type="text" name="SongName" /></p> <p><input type="submit" name="submit" value="Add Song to List" /> <input type="reset" name="reset" value="Reset Song Name" /></p> </form> </body> </html>
- 2 replies
-
- in_array
- songorganizer
-
(and 1 more)
Tagged with:
-
Hi! I have the following code for quick verification of uploaded files: // Validating the Image (file_upload) if (in_array("", $_FILES['file_upload']['name'])) $errorArray['Image File'] = "Browse and select a GIF/JPEG Image File to upload!"; elseif (isset($_FILES['file_upload'])) { foreach ($_FILES['file_upload']['type'] as $key => $type) { if (!($_FILES['file_upload']['type'][$key] =="image/jpeg" OR $_FILES['file_upload']['type'][$key]=="image/gif")) $errorArray['Uploaded Image'] = "Your uploaded file must be either JPG or GIF only!"; elseif (!doesuserfile_nameEventBannerExist($_FILES['file_upload']['name'][$key])) $errorArray['Uploaded Image'] = "Filename already Exists, Rename and Upload again!"; } } I can upload 7 files at one time and there's no error. More than 7 files at one time, I get an error saying: Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/user/imageuploader.php Please help ! Thank you.
-
I'm new to the site here, so I hope this is the right place for this post. It's also from a Wordpress site, but since Wordpress isn't the issue (and my [lack of] programming knowledge is), I figured this wouldn't fit on the Wordpress forums very well. So here's my problem. I downloaded a plugin which I'm trying to modify, and it's breaking my site (internal server error), which always makes for a fun day. Here's the piece I'm inserting: // ---START--- Add Buddypress 'Friends' filter. $wpdb->show_errors(); $k_user_id = $current_user->ID; $k_friends1 = $wpdb->get_col( "SELECT initiator_user_id FROM $wpdb->prefix . 'bp_friends' WHERE friends_user_id = $k_user_id AND is_confirmed = 1" ); $k_friends2 = $wpdb->get_col( "SELECT friends_user_id FROM $wpdb->prefix . 'bp_friends' WHERE initiator_user_id = $k_user_id AND is_confirmed = 1" ); $k_friends = array($k_friends1, $k_friends2); foreach($workers as $x) { if(!in_array($x, $k_friends, TRUE) { unset($workers[$x]); } } $wpdb->hide_errors(); The plugin has already defined the $workers variable, but I'd like to modify that variable by removing any values not contained in either of the two SQL queries. To provide more context, this plugin is an appointments plugin that I'm trying to integrate with Buddypress so that users can schedule appointments with each other, but only if they're friends. I know just enough php to get myself in trouble, so I'm sure there's something that's very obvious to everyone else, but I'm not seeing it...and it's very likely to do with me not understanding exactly how the functions are actually working. Any help would be very much appreciated. Thanks!
- 20 replies
-
- arrayunset
- in_array
-
(and 1 more)
Tagged with: