PHP - Php Array Type?
Is there a way to find out what the array type is?
Example: Code: [Select] $array1 = array('red', 'pizza', '14'); $array2 = array('color' => 'red', 'food' => 'pizza', 'age' => '14'); if(is_recursive($array1)){ return TRUE; } else if(is_multidimensional($array2){ return TRUE; } else { return FALSE; } Similar TutorialsHi friends how does this types of array operate ? pls help, I am repeatedly facing this code but my brain can't hold, i am familiar with multi dimensional array but what are these ? $data[$row['id']] $options['data']=$row[0]; hello friends what does this type of array means ? $data[] = $row; Can anyone let me know what I am doing wrong. I am sure it will (after the fact) be obvious, but I don't see it right now. Wish to remove all array elements which do not implement ValidatorCallbackInterface. Thanks <?php interface ValidatorCallbackInterface{} class ValidatorCallback implements ValidatorCallbackInterface{} function array_filter_recursive($input) { foreach ($input as &$value) { if (is_array($value)) { $value = array_filter_recursive($value); } } return array_filter($input, function($v) { return $v instanceOf ValidatorCallbackInterface; }); } function recursive_unset(&$array) { foreach ($array as $key => $value) { if (is_array($value)) { recursive_unset($value); if(empty($value)) { unset($array[$key]); } } elseif(!$value instanceOf ValidatorCallbackInterface) { unset($array[$key]); } } } $validatorCallback = new ValidatorCallback(); $rules=[ 'callbackId'=>"integer", 'info'=>[ 'arrayofobjects'=>[$validatorCallback], 'foo1'=>'bar1' ], 'foo2'=>'bar2', 'bla'=>[ 'a'=>'aa', 'b'=>'bb', ], 'singleobject'=>$validatorCallback ]; echo('original rules'.PHP_EOL); var_dump($rules); $desiredrules=[ 'info'=>[ 'arrayofobjects'=>[$validatorCallback] ], 'singleobject'=>$validatorCallback ]; echo('desired rules'.PHP_EOL); var_dump($desiredrules); echo('array_filter_recursive'.PHP_EOL); var_dump(array_filter_recursive($rules)); echo('recursive_unset'.PHP_EOL); recursive_unset($rules); var_dump($rules);
original rules array(5) { ["callbackId"]=> string(7) "integer" ["info"]=> array(2) { ["arrayofobjects"]=> array(1) { [0]=> object(ValidatorCallback)#1 (0) { } } ["foo1"]=> string(4) "bar1" } ["foo2"]=> string(4) "bar2" ["bla"]=> array(2) { ["a"]=> string(2) "aa" ["b"]=> string(2) "bb" } ["singleobject"]=> object(ValidatorCallback)#1 (0) { } } desired rules array(2) { ["info"]=> array(1) { ["arrayofobjects"]=> array(1) { [0]=> object(ValidatorCallback)#1 (0) { } } } ["singleobject"]=> object(ValidatorCallback)#1 (0) { } } array_filter_recursive array(1) { ["singleobject"]=> object(ValidatorCallback)#1 (0) { } } recursive_unset array(2) { ["info"]=> array(2) { ["arrayofobjects"]=> array(1) { [0]=> object(ValidatorCallback)#1 (0) { } } ["foo1"]=> string(4) "bar1" } ["singleobject"]=> object(ValidatorCallback)#1 (0) { } }
<?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); error_reporting(E_ALL | E_WARNING | E_NOTICE); ini_set('display_errors', TRUE); if (session_status() == PHP_SESSION_NONE) { session_start(); } if(!isset($_SESSION['login'])) { echo ("<script>location.href='../clogin/'</script>"); die(); } if (isset($_POST['submit'])) { include_once('db.php'); //get post details from user $UserNumber = $_POST['uNumber']; $sql = "SELECT * FROM customer WHERE user_number=?"; $stmt = $connection->prepare($sql); $stmt->bind_param('i', $UserNumber); $stmt->execute(); $result = $stmt->get_result(); $count = $result->num_rows; if($count == 1) { while($row = $result->fetch_assoc()); { $db_Uno = $row['user_number']; if($userNumber !== $db_Uno) { echo'<script>swal.fire("FAILED!!", "<strong>No Customer with the user number you entered.</strong><hr><br/><i> Check well and try Again.</i>", "error");window.setTimeout(function(){ window.location.href = "home.php"; }, 2000);</script>'; exit(); } else { } }//while loop } //end of if rslt }// end submit for transfer post ?>
Not sure how to find what is causing my issue here, I'm running smarty which gives me this error if I switch PHP version to 7.4 (was on 7.3) : - Quote
ERRNO: 8 The line the error refers to is this : -
<p class="cart_del_info_box_text"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <span class="cart_del_info_box_message"><?php echo $_smarty_tpl->tpl_vars['cart']->value->mDelivery['cartdeliverymessage'];?>
How do I go about finding which file has the actual problem? Thanks for any pointers. I have a Windows-style ini file that contains entries as such:
[Timers] Timer(1)=50 Timer(2)=30 Timer(3)=20 The entries represent an array of 3 different timers Apparently parse_ini_file can't deal with the () format. Is there any way to use this format ini file without having to change how arrays are designated? I have a dropdown list which have some elements. I want to get all the elements of the dropdown list into a variable of type array. Any Idea??? CMS: PHP-Fusion version 9.03.110, PHP version: 7.4.16, MySQL Server Version: 5.7.33-log, DB Driver: PDO MySQL My own support people at PHP-Fusion main site have been unable to help me with this problem and I'm hoping for some new eyes and new input on this error. First of all my script works perfectly fine and outputs the result desired. I know that my script is not using PDO prepared statements and I am not prepared to modify it to do so because too much would have to be changed. And I'm not fluent on PDO. My script is an event calendar and can be seen at this url: https://windy.whisperwillow.net/grims_blog/index.php The error only occurs 3 times on 3 lines. <?php echo "<div class='col-sm-12'>\n"; include BASEDIR."grims_blog/include/cal_func_inc.php"; $day=date('d'); $endDate=date('t',mktime(0,0,0,$cMonth,$day,$cYear)); echo "<div><span class='hdspan2'><b>".$locale['gb_510']."</b></span></div><p>\n"; echo "<table class='tbl-responsive' width='67%' align='center' border='0' cellpadding='0' cellspacing='0'><tr>\n"; echo "<td align='center' colspan='3'><img style='max-width:100%;height:auto;' src='".BASEDIR."grims_blog/images/calhead/forest.jpg'></td>\n"; echo "</tr><tr height='30' bgcolor='#960000'>\n"; echo "<td align='left'> <a class='mcaldate' href='".FUSION_SELF."?month=$prev_month&year=$prev_year' title='Last Month'>".$locale['gb_511']."</a></td><td align='center'><span class='mnthhd'>".date("F Y",strtotime($cYear."-".$cMonth."-01"))."</span></td><td align='right'><a class='mcaldate' href='".FUSION_SELF."?month=$next_month&year=$next_year' title='Next Month'>".$locale['gb_512']."</a> </td>\n"; echo "</tr></table>\n"; echo "<table width='67%' align='center' border='0' cellpadding='0' cellspacing='0'><tr><td class='cal-blank'>\n"; echo "<table width='100%' align='center' border='0' cellpadding='0' cellspacing='0'><tr bgcolor='#005E00' height='35'>\n"; foreach ($short_days as $key=>$val) { echo "<th style='text-align:center' width='14%'><span style='font-size:12px; color:yellow;'><b>".$val."</b></span></th>\n"; } echo "</tr><tr>\n"; $s=date('w', mktime (0,0,0,$cMonth,1,$cYear)); for ($ds=1; $ds<=$s; $ds++) { echo "<td class='cal-blank' height='35' style='text-align:center;' valign='middle'></td>\n"; } for ($d=1; $d<=$endDate; $d++) { if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 0) { echo "<tr>\n"; } $result = dbquery("SELECT post_id, post_title, post_date FROM ".DB_GRIMS_BLOG_POST." WHERE active='1' AND MONTH(post_date) = '$cMonth' AND DAY(post_date) = '$d'"); $data = dbarray($result); $stuff1 = $data['post_id'] ? $data['post_id'] : ""; if ($stuff1) { $id = $stuff1; } else { $id = ""; } $stuff2 = $data['post_title'] ? $data['post_title'] : ""; if ($stuff2) { $title = $stuff2; } else { $title = ""; } $stuff3 = strtotime($data['post_date']) ? strtotime($data['post_date']) : ""; if ($stuff3) { $evday = $stuff3; } else { $evday = ""; } if (date("d", intval($evday)) == $d) { echo "<td height='35' class='event' align='center' valign='middle'>\n"; } elseif ($d == $day && $cMonth == date('m') && $cYear == date('Y')) { echo "<td height='35' class='today' align='center' valign='middle'>\n"; } else { echo "<td height='35' class='cal-norm' align='center' valign='middle'>\n"; } if ($d == $day && $cMonth == date('m') && $d <> $evday) { echo "<a class='cal2' href='".BASEDIR."grims_blog/filtered.php?post_id=$id' title='".$locale['gb_513']." $title'><b>$d</b></a>\n"; } elseif ($d == $day && $cMonth == date('m') && $d == $evday) { echo "<a class='cal2' href='#'><b>$d</b></a>\n"; } elseif ($evday) { echo "<a class='ecal' href='".BASEDIR."grims_blog/filtered.php?post_id=$id' title='$title'><b>$d</b></a>\n"; } else { echo "<span class='noevt'><b>$d</b></span>\n"; } echo "</td>\n"; if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 6) { echo "</tr>\n"; } } echo "</table></td></tr></table>\n"; echo "</td></tr></table><p></div>\n"; ?> Well I could not add comments to the posted script. These 3 lines of the db query area give the error in my error log: 1) $stuff1 = $data['post_id'] ? $data['post_id'] : ""; /* Trying to access array offset on value of type bool */ 2) $stuff2 = $data['post_title'] ? $data['post_title'] : ""; /* Trying to access array offset on value of type bool */ 3) $stuff3 = strtotime($data['post_date']) ? strtotime($data['post_date']) : ""; /* Trying to access array offset on value of type bool */ I know I am asking a lot for help on older code but would really appreciate it if someone can take a look. Edited April 19 by OldGrimClarify error lines Hi, WHAT: So I cannot for the life of me figure out why I'm getting this error. I'm trying to create a function that will display the user information from the database in a table but I have like a ton of these errors on the page and I don't know whats wrong. STEPS TO RESOLVE: So I've gone over my code a bunch of types to make sure that all the variables and what not were spelled correctly and as far as I can tell they are. I've also googled this issue to see if I can find a solution but none of them are very helpful. I honestly don't know whats wrong so kinda hard to find ways to resolve an issue, I don't even really know what this error means. THE CODE: This is where I put the function into action <?php display_table( array( "id" => "Id", "emailaddress" => "Email", "firstname" => "First Name", "lastname" => "Last Name", "salesperson" => "Salesperson", "phonenumber" => "Phone Number", "extension" => "Extension", "type" => "Type" ) ); ?> //This is the function <?php function display_table($fields, $data, $rows, $page){ if(isset($_GET['page'])){ $page = $_GET['page']; } else { $page = 1; } $firstRecord = ($page - 1) * ROWS_PER_PAGE; $pageNumbers = ceil($rows / ROWS_PER_PAGE); echo '<div class="table-responsive w-75 mx-auto py-3"> <table class="table table-dark table-bordered table-sm"> <thead> <tr>'; foreach($fields as $key){ echo '<th class="py-2">' . $key . '</th>'; } echo '</tr> </thead> </tbody>'; $keys = array_keys($fields); for($record = $firstRecord; $record < $firstRecord + ROWS_PER_PAGE; $record++){ $row = $data[$record]; echo '<tr>'; for($recordCount = 0; $recordCount < count($keys); $recordCount++){ $column = $keys[$recordCount]; echo '<td class="py-2">' . $row[$column] . '</td>'; } echo '</tr>'; } echo '</tbody> </table'; for($pages = 1; $pages <= $pageNumbers; $pages++){ echo '<a class="btn btn-dark mx-1" href=?page=' . $pages . '</a>'; } } ?> Any help/advice would be really appreciated hi, very strange issue. when I create test e-mail or I will forward the specific e-mail, the script works correctly - saves attachment into server disk. now, when I configure to check another mailbox, it gives me error: Num Messages 11 Fatal error: Cannot use object of type stdClass as array in /test/emailattach/index.php on line 34 index.php: Code: [Select] <?php $mbox = imap_open("{mail.server.com:143}", "email@email", "XXX") or die('Cannot connect to mail: ' . imap_last_error()); // make connection with mailbox and check # messages if ($hdr = imap_check($mbox)) { echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>"; $msgCount = $hdr->Nmsgs; } else { echo "failed"; } $overview=imap_fetch_overview($mbox,"1:$msgCount",0); $size=sizeof($overview); // get message info for($i=$size-1;$i>=0;$i--) { $val=$overview[$i]; $msg=$val->msgno; $from=$val->from; $date=$val->date; $subj=$val->subject; $seen=$val->seen; $from = ereg_replace("\"","",$from); // Check for attachements and store them $struct = imap_fetchstructure($mbox,$msg); $contentParts = count($struct->parts); if ($contentParts >= 2) { for ($ix=2;$ix<=$contentParts;$ix++) { $att[$ix-2] = imap_bodystruct($mbox,$msg,$ix); } for ($k=0;$k<sizeof($att);$k++) { if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") { if ($att[$k]->parameters[1]->value != "") { $FileName[$k] = $att[$k]->parameters[1]->value; $FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4)); } } elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") { $FileName[$k] = $att[$k]->parameters[0]->value; $FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4)); $fileContent = imap_fetchbody($mbox,$msg,$file+2); $fileContent = imap_base64($fileContent); $localfile = fopen("$FileName[$k]","w"); fputs($localfile,$fileContent); fclose($localfile); } } } } imap_close($mbox); ?> Could there be some encoding issue? with thanks, Margus I am getting these errors . This is my complete HTML page. Everything seems to work fine but when i retweet a message these error show up. Here is my tweet.php and the errors are at line 32 and 41. Previously there was an error at line 24: It was like this: '.((!empty($tweet->retweetMsg) && $tweet->tweetID === $retweet['tweetID'] or $tweet->retweetID > 0) ? ' I changed it to this and the error went away '.((isset($retweet['retweetID']) ? $retweet['retweetID'] === $tweet->retweetID OR $tweet->retweetID > 0 : '') ? ' Maybe this could help! I will really appreciate any suggestion coming my way! hi there, i am fairly new to OOPs in php, i get an error when i declare the argument type (as object) in a function and pass the same type (object). class eBlast { public static function getEmail(object $result) { return $result->email; } } $r = mysql_fetch_object($query); eBlast::getEmail($r); echo gettype($r); // outputs: object error is : Code: [Select] Catchable fatal error: Argument 1 passed to eBlast::getEmail() must be an instance of object, instance of stdClass given, called in C:\wamp\www\integra\client\pl_eblast\admin\send_emails.php on line 145 and defined in C:\wamp\www\integra\client\pl_eblast\app\app.eBlast.php on line 8 if i remove the type declaration in the function it works, but just would like to know why it shows error when pass the same type, also isnt mysql_fetch_object is the instance of stdclass? thanks in advance! Hi Guys, I need help I have setup a code recently : this is the code : $za['MIN(spec_positionid)'] and it gave me an error saying : Cannot use object of type stdClass as array but if I change to this : $za->spec_positionid it works, but I need to get the MIN value from the database. can someone please help. this is very urgent for me..... Probably a stupid question . . .
The MIME type in my php.ini file is set to text/html:
default_mimetype = "text/html"But, because I use XHTML 1.0 Strict, the MIME type of my web pages is set to text/xml: <meta http-equiv="content-type" content="text/xml; charset=utf-8" />I should therefore change the php.ini MIME type to text/xml, right? I have a Form and need to loop through 10 fields on it. Which Looping Structure would be best and why? In PHP, I believe my choices are... - For Each - Do While - While Thanks, Debbie Hello, Does anyone know how may i detect the Connection type by user IP? Broadband etc. $_GET['id'] = (empty($_GET['id'])) ? 0 : $_GET['id']; I'm going over someones code, the site is super flawed, Ive got to much going on at once and I can't wrap my head around that. Is it if the string is empty or 0 then use the get variable or is it something else? Hey In my spare time, I am working on my PHP framework. Now, to help with development and quickly discover where I miss a type cast, I have adopted to check all parameters that are passed to a method using a function. For instance: public function __construct(&$target = null, $depth = 1){ $this->validateArguments( array(1 => 'int'), array(1 => $depth) ); And the code that triggers the exception: public function testPhpFreakType(){ $obj = 1; $p = new Xcms_DataStructures_Pointer($obj, "1"); } Code: [Select] 0: |--------------------------------------------------| 1: |--Exception: 4cfe2e86ca5970.22624423 - Full Trace | 2: | Tue, 07 Dec 2010 13:54:30 +0100 3: |-Class: 4: | Xcms_Exceptions_InvalidArgument 5: |-Message: 6: | Argument #1 of Xcms_DataStructures_Pointer:__construct() is no _null:int 7: | Stack offset: 3 8: | 9: |-Trace 10: | #0 D:\www\xcms_rev\core\exceptions\invalid.argument.helper.class.php(133): Xcms_Exceptions_InvalidArgumentHelper::factory(1, '_null:int', NULL, 2) 11: | #1 D:\www\xcms_rev\core\basic.class.php(80): Xcms_Exceptions_InvalidArgumentHelper::validateArguments(Array, Array, Array, 1) 12: | #2 D:\www\xcms_rev\core\data.structures\pointer.class.php(49): Xcms_Basic->validateArguments(Array, Array) 13: | #3 D:\www\xcms_rev\core\data.structures\pointer.test.php(73): Xcms_DataStructures_Pointer->__construct(1, '1') 14: | #4 [internal function]: Xcms_DataStructures_PointerTest->testPhpFreakType() 15: | #5 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(737): ReflectionMethod->invokeArgs(Object(Xcms_DataStructures_PointerTest), Array) 16: | #6 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(627): PHPUnit_Framework_TestCase->runTest() 17: | #7 C:\xampp\php\PEAR\PHPUnit\Framework\TestResult.php(629): PHPUnit_Framework_TestCase->runBare() 18: | #8 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(575): PHPUnit_Framework_TestResult->run(Object(Xcms_DataStructures_PointerTest)) 19: | #9 C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php(766): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult)) 20: | #10 C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php(742): PHPUnit_Framework_TestSuite->runTest(Object(Xcms_DataStructures_PointerTest), Object(PHPUnit_Framework_TestResult)) 21: | #11 D:\www\xcms_rev\core\testing\manager.class.php(83): PHPUnit_Framework_TestSuite->run() 22: | #12 D:\www\xcms_rev\core\testing\manager.class.php(56): Xcms_Testing_Manager->testClass(Object(ReflectionClass)) 23: | #13 D:\www\xcms_rev\cache\pkg\scripting\script_1.php(3): Xcms_Testing_Manager->run(Object(Xcms_Url_DefaultRequest)) 24: | #14 D:\www\xcms_rev\core\util.lib.php(340): include('D:\www\xcms_rev...') 25: | #15 D:\www\xcms_rev\core\packages\scripting\controllers\scripting.controller.php(66): Xcms_Util::sandboxedInclude('cache/pkg/scrip...', Array) 26: | #16 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(210): Xcms_Packages_Scripting_Controllers_ScriptingController->execute(Object(Xcms_Packages_Scripting_Models_ScriptModel), Object(Xcms_Templating_Context)) 27: | #17 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(170): Xcms_Mvc_Controllers_DefaultController->runScript(1, 0, Object(Xcms_Templating_Context)) 28: | #18 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(132): Xcms_Mvc_Controllers_DefaultController->runScripts(0, 0, Array, Array, 1, 0) 29: | #19 D:\www\xcms_rev\index.php(15): Xcms_Mvc_Controllers_DefaultController->run() 30: | #20 {main} 31: |--------------------------------------------------| I think this speeds up my development quite a bit, because I can catch errors very early in the development process. I can give multipe possibilities of what is allowed for each parameter, not just a single possibility. Also, it is possible to register custom type/validity-checks on both global and local scope. One thing I do worry about, however, is the the performance. Of course, I could just make the funciton do nothing in production code, if it takes too much time, or I could write a script to remove all calls to that function. When I started learning python a while back, the concept to just code to interfaces instead of types seemed very intuitive and made my code much more flexible. Of course that is what I do with PHP as well, but I it's not entirely the same. So now, coming back at my PHP code and having introduced features of static languages such as type checking, I worry about whether that is the right approach. What are your thoughts on the matter? Long story short, this is my code: Code: [Select] <input type=radio id='s1' value='1' onclick='showPreview(1)' name='star' $value><label for='s1'><img src='style_images/1/icons/1.png'></label> <br> <input type=radio id='s2' value='2' onclick='showPreview(2)' name='star' $value><label for='s2'><img src='style_images/1/icons/2.png'></label> <br> <input type=radio id='s3' value='3' onclick='showPreview(3)' name='star' $value><label for='s3'><img src='style_images/1/icons/3.png'></label> <br> <input type=radio id='s4' value='4' onclick='showPreview(4)' name='star' $value><label for='s4'><img src='style_images/1/icons/4.png'></label> <br> <input type=radio id='s5' value='5' onclick='showPreview(5)' name='star' $value><label for='s5'><img src='style_images/1/icons/5.png'></label> Somehow I need to try to get my $value to equal 'checked' based upon my "star" variable: So I choose #5, which is <input type=radio id='s5' value='5' onclick='showPreview(5)' name='star' $value> and now my "star" value is set to 5, (I updated it through my db) how do I make $value become 'checked' when I have 4 others input type=radio's that it will check also? I only need the #5 one checked as that is one that I chose. The problem is, I have 70 of these input type Radio's and if I use $value on every one it will not show them all checked instead of just the 1 i chose |