PHP - In_array() [function.in-array]: Wrong Datatype For Second Argument
Im getting a warning with in_array.I have used if() inside for loop to check if value has already been printed or not. If not it will print and save the value in $done[].Can someone please point me out my mistake that i am getting a warning.
Code: [Select] <?php for($i=0;$i<=$count;$i++) { $count_final = explode("_", $result[$i]); if (in_array($count_final[0],$done)) { //Line 480 echo "<tr>"; echo"<td>$count_final[0]</td>"; $templ = $count_final[0]."_left"; $tempr = $count_final[0]."_right"; $cleft = $count_middle[$templ]; $cright = $count_middle[$tempr]; echo"<td>$cright</td>"; echo"<td>$cleft</td>"; echo "</tr>"; $done[] = $count_final[0]; } } ?> Code: [Select] Warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\Users\\Desktop\yyy.php on line 480 Similar TutorialsHello I'm using tcpdf to convert some stuff to pdf. On my local computer running wamp my script works perfect and the pdf is generated without problems When i put my files in a webserver i got this error: Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/vieira/public_html/topdf/dbcon.class.php on line 68 Line 68 is: if(in_array($key,$arr_switches)){ //check switches My complete code is: // Get fields of enum on/off switches type $result2 = mysql_query("SHOW FIELDS FROM $db_name.$table"); $counter=0; while($row = @mysql_fetch_array($result2)){ //echo $row['Field'] . ' ' . $row['Type']."<br/>"; if($row['Type'] === "enum('on','off')"){ $arr_switches[$counter] = $row['Field']; $counter++; } } //print"<pre>"; print_r($arr_switches); print"</pre>";exit; $counter = 0; while($row = @mysql_fetch_array($result)){ foreach( $row as $key => $val ){ if(!is_numeric($key)) { $row_rs_certidao[$key] = $val; if(in_array($key,$arr_switches)){ //check switches $record_key[$counter] = htmlentities('<?php if (!(strcmp($row_rs_certidao['."'".$key."'".'],"on"))) {echo "x";} ?>'); if($val==='on') $record_val[$counter] = "x"; //turn on switches else $record_val[$counter] = ''; //turn off }else{ $record_key[$counter] = htmlentities('<?php echo $row_rs_certidao['."'".$key."'".']; ?>'); $record_val[$counter] = htmlentities($val); } $counter++; } } } Anyone can help? I am having some problems getting a query correct. Basically I have two tables, one with listings and another with categories. In the listings table I have a column called shortdescription. I am trying to pull the shortdescription from the listings table with the query $shortdesc = array_shift(mysql_fetch_row(mysql_query("select shortdescription from links where category = '".$scat->id."' "))); The shortdecription display properly on the pages display the listings, however I am getting the following error on any pages that only display the parent categories Warning: array_shift() [function.array-shift]: The argument should be an array in /home/...path/file.php on line 1462 The listings id numbers begin at 75+ because the initial parent category id ends at 74. The query seems to be searching for listing ids below 75 and spitting out an error because it is not finding them. Any ideas on how to eliminate this error and/or stop the query from looking for non-existant data? Hi there, I am currently using the in_array() function to check the user's country with the country in the ShippingProfile table. I have a function that returns the shipment profile info from the table. $myshipProfile = filter_shippingprofile(array(......)); And in the $myshipProfile I get the profile info with the countryID. Now I can check the user's country in the array: if(in_array($_SESSION['userCountryId'], $myshipProfile)) { print "yes country is found"; } I works fine so far. But there is a slight problem to it. I did a quick: print_r($myshipProfile); And the output was: Array ( [shippingprofileID] => 14 [supplierId] => 66 [shippingprofilename] => ProfName1 [shippingto] => CustomCountries [ShipRegionCountries] => 66 [shippingcost] => 10 Notice the supplierId and the ShipRegionCountries has the same value. And now when I try to perform in_array() it will return true every time even if the ShipRegionCountries is not 66 because as supplierID is 66. You see the conflict. Therefore, can we write like this: if(in_array($_SESSION['userCountryId'], $myshipProfile['ShipRegionCountries'])) { print "yes country is found"; } I get no ouput for this. Whats the correct way to check only the 'ShipRegionCountries' in the array? Thank you Can someone please help me figure this out: I have a normal text file with 3 lines in it, every line contain one date i.e 12112011 (12.11-2011). I put the content of that file in an array, and want to compair the dates in the text file against the date generated from the loop. Problem is, i can only get a match for the last date listed in the text file no matter what.. If i have 4 dates in the file, it only style the last date. Thanks! --- CODE SNIPPET --- $day_num = 1; $days_in_month = 30; $month = 11; $year = 2011; //Access the file containing already taken dates and load them in an array: $date_array = file("test.txt"); //count up the days, untill we've done all of them in the month and check them against the dates in the text file: while ($day_num <= $days_in_month) { // Set the variable $date to be checked against the content of the array: $date = $day_num . $month . $year; if (in_array($date, $date_array)) { echo "<td class='color_green'>$day_num</td>"; //print_r($date_array); } else { echo "<td>$day_num</td><br />"; } $day_num++; } Hello, I've been curious why the following won't work. Could anyone show me what I am doing wrong. The code is to find the TLD in a URL. Code: [Select] $a[] = parse_url( 'www.example.com' ); $tld_arr = array ( 'com', 'net', etc...); for ($i=0; $i<count($this->a); $i++) { if (in_array ( $this->a[$i]['host'], $tld_arr) ) < This is what I'm curious about { //do something } // do something else } Thank you Hi all. I've got this bit of code: $needles=array(`.`,`..`,`css`,`php`,`input_forms`); $t1=scandir($_SERVER['DOCUMENT_ROOT']); foreach($t1 as $t1_value){ if(!is_dir($t1_value)){ unset($t1[array_search($t1_value,$t1)]); }else{ unset($t1[array_search($needles,$t1)]); } } As you can see, I'm trying (in the else statement) to array search $t1 for everything in $needles, then unset the matches from $t1. But its not working and I'm not sure why. I also tried... unset($t1[array_search(in_array($needles,$t1),$t1)]); But that doesn't work either. It only removes the "." directory from the array. Any ideas on what's going wrong? Hello, Currently have an array like looks like the following when using print_r($session->items): Array ( [F1225] => 1 [EDS11147317] => 1 [1156D6RE001] => 1 [I111ADE47946] => 1 [S679AQ339] => 1 [S67914599] => 1 [CH111337631254] => 1 [S6787903647] => 1 [A11144O189] => 1 [F11144520] => 1 [121584Q12] => 1 [I11144661ADE] => 1 [S678829NB] => 1 ) I am trying to check if an item is in the array and if so, display a different result but currently every item says it is in the array when they are not (unless my logic is off...from the items I am looking at some should be included and some should not..but the below code is showing every item as having the same result). Example: foreach ($items as $item) { if (in_array($item->ItemID, $session->items)) { //$session->items is the array output above echo "In Array"; } else { echo "NOT in Array"; } } Currently everything say "In Array" when some should not. Am I using the in_array incorrectly? Thanks Everyone. Hi, I am attempting to export some table data to an excel spreadsheet. I am having trouble with the final few lines and getting the following error within the spreadsheet (which is otherwise working well). Quote The argument should be an array in/home/website/public_html/student_list_export.php on line 34 I get the same error message for the line below also (echo implode("\t", array_values($row)) . "\n". I'm at a loss. This seems like a pretty obvious and direct error message but I can't get it working properly. Can somebody please help me? Below is the code I am working with. <?php include('includes/admin_session.php'); require_once("includes/connection.php"); function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } // file name for download $filename = "student_list_" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel"); $flag = false; $result = mysqli_query($connection,"SELECT * FROM students ORDER BY tutor") or die(mysqli_error($connection)); while(false !== ($row = mysqli_fetch_assoc($result))) { if(!$flag) { // display field/column names as first row echo implode("\t", array_keys($row)) . "\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\n"; } ?> Firstly i am new to php.Iv currently got this while loop iterating through a database drawing polygons from the info in the datatable.each polygon has its own id stored in the datatable and with the on click event i am trying to just output to the screen the specific id of the polygon clicked on.It looks ok to me but it doesnt work for some reason. Below is the loop and the function it is trying to call. /////////////////////////////////////////////////////////////////////// <?php while($info = mysql_fetch_array( $data )){ echo "<polygon fill=".$info['fill_colour']." stroke=\"black\" id=".$info['id']." onclick=\"buildingClick(id)\" points=".$info['coordinates']." />"; } ?> ///////////THIS IS THE FUNCTION/////////////////////////// <?php function buildingClick($id) { echo "building id : {$id}"; } ?> /////////////////////////////////////////////////////////////////// If anyone could help it would be hugely appreciated. Eoin I'm getting this error, but I'm not sure how to fix it (on my Wordpress site). Warning: usort() [function.usort]: The argument should be an array in /home2/lushwebs/public_html/4mulaevents/wp-content/themes/dailyedition/includes/talking-points.php on line 20 Warning: Invalid argument supplied for foreach() in /home2/lushwebs/public_html/4mulaevents/wp-content/themes/dailyedition/includes/talking-points.php on line 22 Any help appreciated. Thanks! Hello all, I just created this function that I want to use in CLi mode. It works perfectly in regular browser mode, but gives me this error on Cli mode if I do convertToCamelCaps('TEST STRING'); PHP Catchable fatal error: Argument 1 passed to convertToCamelCaps() must be an instance of string, string given in file... if (!function_exists('convertToCamelCaps')) { function convertToCamelCaps(string $string, $initialCaps=FALSE) { if ($words = explode(' ',$string)) { foreach ($words as $index => &$word) { $word = strtolower($word); if($index==0 && $initialCaps===FALSE) { continue; } $word = ucwords($word); } return implode('',$words); } return FALSE; } } If I remove the string datatype requirement in the function before the function argument list, it works fine in CLi mode. if($_POST['Submit']=="Check"){ $issueid=(int)$_POST['issueid']; $returndate=mysql_real_escape_string($_POST['returndate']); list($temp)= mysql_fetch_row(mysql_query("select issueid FROM issue where issueid='$issueid'")); if($temp!=NULL){ $insert_query="insert into returning values($issueid,'$returndate')"; $result=mysql_query($insert_query,$linkID1); if($result){ list($bookid,$account,$issuedate,$duedate)= mysql_fetch_row(mysql_query("select bookid,account,issuedate,duedate FROM issue where issueid='$issueid'")); list($title,$name,$fine)= mysql_fetch_row(mysql_query("select title,name,fine FROM book,user where bookid='$bookid' AND acc='$account'")); $insert_book="update book set copies=copies+1 where bookid='$bookid'"; $result=mysql_query($update_book,$linkID1); Quote i want to take difference of $duedate and $returndate and store it to another variable checks that variable for number of days in it http://php.net/manua...ssword-hash.php shows a simple example to hash a password using BCRYPT. I've read different posts recommending CHAR(60), BINARY(60), BINARY, and even BINARY(40).
What are the pros and cons of using one datatype over another?
<?php /** * In this case, we want to increase the default cost for BCRYPT to 12. * Note that we also switched to BCRYPT, which will always be 60 characters. */ $options = [ 'cost' => 12, ]; echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options)."\n"; ?> Hi every one, Here is the problem.. I have a string which looks like this '(243/433)*100' , i want to calculate its value, but dont know how to do. if i use type conversion then value becomes zero. Please help. I was wondering just a general question here. I am just going through a text book on the main aspects of a problem solving approach to PHP, but when I was just trying out one of my own theories on this particular one of my own: <html> <body> <h1>User Input set as functions</h1> <tt>Please enter a value below:</tt> <br> <form id="userInput" name="userInput" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> <input type="text" id="input" name="input" value="" /> <input type="submit" value="Send This" /> </form> <?php function mistake($errorvalue) { echo $errorvalue; } function getValue($userInput) { return $userInput; } if(!isset($_GET['input']) || $_GET['input'] == '') { mistake("No value received yet!"); // calls the error function } else { $input = $_GET['input']; echo "You did enter something, this was: "; $userInput = getValue($input); echo "$userInput"; } ?> </body> </html> I am quite impressed with what I have done there, though I know its nothing special and could obviously be done not using functions at all, just wanted to see if I could get one that returns something, in this case the 'getValue()' function. But when I've set it to work out what type of variable ie gettype is it? (going off completely memory here), its always a string, even if all I do is enter a 1, even tried not using the GET method for the form and used the POST one instead it still says that a single integer is a string. Why just out of question is it doing this? Just quite interested thats all. Thanks for your time and I look forward to any replies, Jeremy. When ever I put it on my php page I get a blank page. I haven't been able to call the function yet. function waitmsg($dmsg,$whereto) { echo "<script language='javascript'>setTimeout("location.href='http://".$site_url."/".$whereto."'",5);</script>"; echo "<br><br><br><div align='center'>".$dmsg."</div><br>"; echo "<div align='center'>Please wait while you're automatically redirect, If you are not forwarded within 5 seconds, please click <a href='http://".$site_url."/".$dmsg.">here</a>.</div><br><br><br>"; } Any ideas? Have I made this function correctly? $info = fetch_user_info_by_id(); is an array. Can I just pull check the values with if (($info['totalrequested'] === 0) && ($info['accounttype'] === 1)) or do I need to do something else? Code: [Select] function capital_requested_reminder() { $info = fetch_user_info_by_id(); if (($info['totalrequested'] === 0) && ($info['accounttype'] === 1)) { return true; } } Hey, it looks like theres something wrong with my function to validate a user, but i dont know what it is? Code: [Select] function SQL_VALID_USER($name, $pass, $email) { //if(SQL_PINK() == 1) { $query = sprintf("SELECT accountname, accountpassword, accountemail FROM members WHERE accountname = '%s', accountpassword = '%s', accountemail = '%s'", mysql_real_escape_string($name), mysql_real_escape_string($pass), mysql_real_escape_string($email)); $result = mysql_query($query); if (!$result) { return 0; } else { $_SESSION['auth'] = 1; return 1; } //} } Thanks for looking at it Code: [Select] <?php $a = array(3, 4, 18, 15); $b = array(12, 10, 11, 24); $c = array(5, 6); $d = array(7, 8, 13); $e = array(19, 16); function test($ID) { if(in_array($ID, $a)) { echo "a"; } if(in_array($ID, $b)) { echo "b"; } if(in_array($ID, $c)) { echo "c"; } if(in_array($ID, $d)) { echo "d"; } if(in_array($ID, $e)) { echo "e"; } } $test = 3; test($test); ?> Why doesn't that echo "a" I don't really get what I am doing wrong, any help is appreciated Code: [Select] <?php function dbConnect($usertype, $connectionType = 'mysqli') { $host = 'localhost'; $db = 'gallery'; if ($usertype == 'read') { $user = 'psread'; $pwd = '####'; } elseif ($usertype == 'write') { $user = 'pswrite'; $pwd = '####'; } else { exit('Unrecognized connection type'); } if ($connectionType == 'mysqli') { return new mysqli($host, $user, $pwd, $db) or die ('Cannot open database'); } } ?> when i call upon the function i get this message Fatal error: Call to a member function query() on a non-object in C:\webs\phpsolutions\comments.php on line 8 from this code Code: [Select] <?php require_once('includes/connection.php'); // connect to MySQL $conn = dbConnect('write'); // prepare the SQL query $sql = 'SELECT * FROM images'; // submit the query and capture the result $result = $conn->query($sql) or die(mysqli_error()); // find out how many records were retrieved $numRows = $result->num_rows; ?> |