PHP - Var_dump Of An Array Shows Just One Variable
The var_dump of the $cart_items array is supposed to show an array of $cart_items with the quantities added together for the same id but it doesn't even show an array, it just shows one value. session_start(); $cart_items = $_SESSION["cart_items"]; if ( $cart_items == null ) { $cart_items = array(); } if ( isset($_REQUEST["element_id"]) ) { $id = $_REQUEST["element_id"]; } if ( isset($_REQUEST["quantity"]) ) { $quantity = $_REQUEST["quantity"]; } if ( isset($id) && isset($quantity) ) { if (isset($cart_items[$id])) { $cart_items[$id] += $quantity; } else { $cart_items[$id] = $quantity; } } var_dump($cart_items);
Similar TutorialsWhenever I try and post a form with radio buttons like this
<input type="radio" name"whatever" value="0">and I do a var_dump($_POST)it always shows array(11) {["whatever"]=> string(2) "on" }but this works and will display 1 in the var_dump <input type="radio" name"whatever" value="1">Why is this. I need the value set to 0 because that's the value going into the database. I don't really want to do a str_replace just to replace "on" with "0" when I send a post variable to another page for processing using cURL and then I echo the variable I am getting extra slashes and periods this is where I set the fields to send. Code: [Select] curl_setopt($ch, CURLOPT_POSTFIELDS,"name='. $name .'&email='. $email .'&serial='. $serialnumber .'"); this is what happens when I echo $serial on the processing page. Code: [Select] \'. SLNM7IV6ZM98YJRXO8D5 .\' it should look like Code: [Select] SLNM7IV6ZM98YJRXO8D5 I have peice of code which is designed enter a question into a database and the username of the person who asks the question. However, the code enters <?php echo Array; ?> into the database and not 'Tom'. I am using the same code which inserts the category of the question in the database which works. But the username comes up as <?php echo Array; ?>. Does anyone know why it shows "array"? Code: [Select] if($loggedIn) { echo "Welcome, ".$user['username'].". <a href=\"logout.php\">Logout</a>. <table width='300' border='0' align='center' cellpadding='0' cellspacing='1'> <tr> <td><form name='form1' method='post' action='phpviewquestion.php'> <table width='100%' border='0' cellspacing='1' cellpadding='3'> <tr> <td colspan='3'><strong>Your Question</strong></td> </tr> <tr> <td width='71'>Question</td> <td width='6'>:</td> <td width='600' height='50'><input name='question' type='text' id='question'></td> <td width='71'>Notes</td> <td width='6'>:</td> <td width='600' height='50'><input name='notes' type='text' id='notes'></td> </tr> <tr> <td colspan='3' align='center'><input type='image' name='image' value='Submit' src='http://www.domain.co.uk/images/submitbutton.PNG' name='image' width='100' height='53'></td> <input name='category' type='hidden' value='Furniture' id='category' > <input name='questionmaker' type='hidden' value='<?php echo $username; ?>' id='questionmaker' > </tr> </table> </form> </td> </tr> </table> </div> " ; } else { echo "Please <a href=\"login.php\">Login</a>."; } ?> Hello guys, i had seen the function var_dump() is used in many coding but even i don't know about the function. Can anybody explain what is the purpose of var_dump() function ? if you can explain it with examples then it will be more easy to save it my memory. strange i want to update ProductDescription i get the parsed $pdescription it is echoed but it's regarded as empty by var_dump Code: [Select] <?php // example of how to use basic selector to retrieve HTML contents include('../simple_html_dom.php'); $links=array("http://www.example.com/apartments/198.htm"); foreach($links as $page) { $phtml = file_get_html($page); // find all td tags with attribite align=center foreach($phtml->find('span[id=lblCodiceAppartamento]') as $name){ echo $name->plaintext.'<br><br>'; } foreach($phtml->find('span[id=lblDescrizione]') as $pdescription){ echo $pdescription.'<br><br>'; } $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("international", $con); $query=mysql_query("UPDATE products_NEW SET ProductDescription='$pdescription' WHERE ProductName = '$name->plaintext' AND SupplierID = '38'"); var_dump($query); //mysql_query("INSERT INTO apartments (name) //VALUES ('$name->plaintext')"); mysql_close($con); } Hi guys im in the middle of optimizing code.. Code: [Select] $sql = "SELECT * FROM sa_enemystats WHERE username='$username'"; $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) { $enemy['current_health'] = $row['current_health']; $enemy['current_skill'] = $row['current_skill']; $enemy['level'] = $row['level']; $enemy['damage'] = $row['damage']; $enemy['evade'] = $row['evade']; $enemy['accuracy'] = $row['accuracy']; $enemy['speed'] = $row['speed']; $enemy['luck'] = $row['luck']; echo 'debug: variables synced with db table'; }I know that the setting of these variables are messy and can be done in a better way... but how? I have tried foreach and copying other's code for an array copy but it lead no where. Then again my syntax could be wrong... I used something like Code: [Select] foreach ( $enemy[$value] as $row => $value) { $enemy[$value] = $row[$value]; } I need a help in the following : I have an admin page from where the admin attaches an gif image.This attached image should be shown to the user as a scrolling image. The code for the scrolling image is done through javascript. So my actual problem is getting the name of the attached gif image to the javascript array which is used for scrolling horizontally. hi all, I have an language pack for example: languages/en.php: Code: [Select] $en['mail']['letter closing'] = "regards,\n your friend!"; and in my config: Code: [Select] $language = "en"; $include_language = @include("languages/".$language.".php"); if(!($include_language)) { $try_default_language = @include("languages/nl.php"); if(!($try_default_language)) { echo "kan de taalpakket niet vinden<br>"; echo "Could not find the language pack.<br>"; echo "example on error: ".$test." shows nothing"; exit; } } In my function I want to include the language pack for example i have $language = 'en' so I want to include $en['general']['letter closing'] I will do this: Code: [Select] global $language,${$language}['general']; But that gives an error unexpected '[' blah blah. How can i call the variable variable array in the valid php way? Code: [Select] $word = 'numbers'; $numbers= array('1', '2', '3', '4'); echo $$word[0]; I expected the output to be '1'. It ended up being nothing... Why does this not work? Is it not possible to have a variable variable array? And if not, is there a workaround? Cheers, Joe hello all, I have an array value in my post array ($_POST['check0'] ) that I am trying to break up into php variables. For some reason if I do this: $var1 = $_POST['check0'][0]; all I get is the first letter of the string from the first value of the array? Hi Everyone
Please checkout the below code:
foreach ($joiners as $joiner) { $town = explode(',', $joiner['address']); if (isset($town[2])) { $town = $town[2]; $get_available_towns[] = $town; $get_available_towns = array(); }
foreach ($joiners as $joiner) { $town = explode(',', $joiner['address']); if (isset($town[2])) { $town = $town[2]; $get_available_towns[] = $town; $get_available_towns = array(); }I don't really understand what is happening. I know the code and everything is correct and it works but I really don't understand how the loop, arrray and variable is working. I wanted to print_r the $get_available_towns outside the loop but it would not work without the square brackets but also I did not even know the square brackets were required. The point was to loop through the data and print all the values. I understand how loops, array's and variables work but I've not seen them used like this. This makes me think I am missing some basic knowledge but I have looked around and I can't see any examples of how loops and arrays are used like this. I have also checked the php manual but still no joy. Can you guys tell me where I could find the information that would have examples on how something like the above code would work? Hi, I am basically trying to apply a different amount to $defineMe for certain numbers of an array .. in this case it's array numbers 11 - 16 Code: [Select] <?php if ($defineNumber > 11 and $defineNumber < 16) { $defineMe = 35.00; } else { $defineMe = 50.00; } $defineNumber[01] = array('name'=>'Product 1'); $defineNumber[02] = array('name'=>'Product 2'); $defineNumber[03] = array('name'=>'Product 3'); $defineNumber[04] = array('name'=>'Product 4'); $defineNumber[05] = array('name'=>'Product 5'); $defineNumber[06] = array('name'=>'Product 6'); $defineNumber[11] = array('name'=>'Product 11'); $defineNumber[12] = array('name'=>'Product 12'); $defineNumber[13] = array('name'=>'Product 13'); $defineNumber[14] = array('name'=>'Product 14'); $defineNumber[15] = array('name'=>'Product 15'); $defineNumber[16] = array('name'=>'Product 16'); ?> Hi, I need help with this, I am quite new to arrays. This one works fine: echo array_sum(array(34,19,22,17,7,22,8,23,17,31,21,32,7,29,13,7))/count(array(34,19,22,17,7,22,8,23,17,31,21,32,7,29,13,7)); which gives "19..." it gets average number. What I want to put the values in the array in a variable so I do this: $t = "34,19,22,17,7,22,8,23,17,31,21,32,7,29,13,7"; so why can't I use array like this: echo array_sum(array($t))/count(array($t)); I need to use variable in array, please someone help. Hey, im struggeling with a small piece of code.... Thats my code: Global $user_ID; $user_ID = get_current_user_id(); echo"User number $user_ID is loggedin";
Echo gives me this:
Now i want to add it to my array: $atts['href'] .= $user_ID . 'abc'; 'href' is set to "https://test.com/" What im getting now ist https://test.com/abc
Can someone tell my why the '2' is missing??
Hello Guys. I have a question here.. I have a photo upload script that uploads photos to the server and then sends the photo name to another page via POST. I only have one var name called $image_all when I echo it this is what I get (When uploading 2 files) Code: [Select] This is the list 2011-12-05_0751.png,2011-12-05_0747.png I also tested with "explode" Code: [Select] print_r(explode(',', $image_all, 10)); and I get this Code: [Select] Array ( [0] => 2011-12-05_0751.png [1] => 2011-12-05_0747.png [2] => What I would like for it to do is assign an incremental var name to each image uploaded and passed in the POST. Like this $image1 = 2011-xx.png $image2 = 2011-xx.png $image3 = 2011-xx.png It should created the variable names dynamically based on the number of images (Up to 10) Thanks for your help! Hello. Can someone show the syntax to echo the variable from the array below that is showing "2010-08-31 23:19"? I need to grab that date and use it elsewhere in my script. Thanks. Code: [Select] array(19) { ["name"]=> string(8) "com_jumi" ["params"]=> array(0) { } ["mainframe"]=> &object(JSite)#2 (6) { ["_clientId"]=> int(0) ["_messageQueue"]=> array(0) { } ["_name"]=> string(4) "site" ["scope"]=> string(8) "com_jumi" ["_errors"]=> array(0) { } ["requestTime"]=> string(16) "2010-08-31 23:19" } Is this right? $admin = array('24.68.200.235','24.68.214.97'); $visitor_ip = $_SERVER['REMOTE_ADDR']; if($visitor_ip == $admin) { echo "k"; } else { die("dead"); hello, um i got a form that stored an array of variables upon users clicks. it submits to another page fine as an array and i can print them using if(!empty($_POST['langSpoken'])) { echo "\n<p><strong>You selected the following LangSpoken:</strong></p>\n<ul>"; foreach($langSpoken as $lang) { // exclude any items with chars we don't want, just in case someone is playing if(!preg_match('/^[-A-Z0-9\., ]+$/iD', $lang)) continue; // print the lang echo "\n\t<li>" . htmlspecialchars($lang) . "</li>"; } echo "\n</ul>"; } else { echo "\n<p>No items selected</p>"; } it prints a list a of array like english spanish but i need to store each one in one variable so i can store in a database is there a way? thanks I use a CURL script API with the header "$headers[] = 'Content-Type: application/json';" The script ends with "$result = curl_exec($ch);" If I simply echo the $result to my browser, I get an array that looks like this:
stdClass Object
[toAddress] => stdClass Object Do I really need to "json_decode" this array? I've spent 2 1/2 days trying every which way, with every permutation to access that one value:
echo $result["fromAddress"]["phone"]; Unfortunately I must have fallen asleep during the array lesson in PHP class ? Thank you. |