PHP - Too Many Variables Vs Arrays
Hi,
Which one is better from performance view (CPU usage and etc)? using too many Variables or a single Associative Array or generally an Array? This one: $ld_linkdump_title = get_option('ld_linkdump_title'); $ld_linkdump_widget_title = get_option('ld_linkdump_widget_title'); $nw_option = get_option('ld_open_nw'); $ld_open_branding = get_option('ld_open_branding'); $ld_stylesheet_option = get_option('ld_stylesheet'); $ld_number_of_links = get_option('ld_number_of_links'); $ld_number_of_links_widget = get_option('ld_number_of_links_widget'); $ld_number_of_rss_links = get_option('ld_number_of_rss_links'); $ld_number_of_links_be = get_option('ld_number_of_links_be'); $ld_repeated_link = get_option('ld_repeated_link'); $ld_linkdump_fd = get_option('ld_linkdump_fd'); $ld_linkdump_rss_desc = get_option('ld_linkdump_rss_desc'); $ld_branding_bg = get_option('ld_branding_bg'); $ld_archive_days = get_option('ld_archive_days'); $ld_archive_pid = get_option('ld_archive_pid'); $ld_show_counter = get_option('ld_show_counter'); $ld_show_description = get_option('ld_show_description'); $ld_show_description_w = get_option('ld_show_description_w'); $ld_send_notification = get_option('ld_send_notification'); $ld_auto_approve = get_option('ld_auto_approve'); $ld_short_url = get_option('ld_short_url'); or this: $options['ld_linkdump_title'] = get_option('ld_linkdump_title'); $options['ld_linkdump_widget_title'] = get_option('ld_linkdump_widget_title'); $options['nw_option'] = get_option('ld_open_nw'); . . . Similar TutorialsHowdy, I used to have a whole bunch of terms (PreK, Elem, MS, HS etc...) together into a single variable called "levels". They terms were separated by commas. The following code created a pulldown menu that allowed me to "filter" the page for any one particular term. Worked terrific... Code: [Select] <? //remove any old level from query $tmp = array(); foreach ($_GET as $fld => $val) if ($fld != 'levels') $tmp[] = $fld . '=' . $val; $page_name = $_SERVER['SCRIPT_NAME'] . '?' . implode('&',$tmp); ?> <?php echo ' <form name="form4" action="" method="get" class="tight"> <select name="levels" >'; ?> <option <?php if(empty($_GET['levels'])){ echo "selected=\"selected\""; } ?> value="<?php echo "$page_name" ?>">DISPLAY ALL LEVELS</option> <?php if ($_GET[levels] == 'PreK') { echo '<option selected value="'; ?> <?php echo "$page_name" ?> <?php echo '&start=0&levels=PreK">PreK</option>'; } else { echo '<option value="'; ?> <?php echo "$page_name" ?> <?php echo '&levels=PreK">PreK</option>'; } if ($_GET[levels] == 'Elem') { echo '<option selected value="'; ?> <?php echo "$page_name" ?> <?php echo '&start=0&levels=Elem">Elem</option>'; } else { echo '<option value="'; ?> <?php echo "$page_name" ?> <?php echo '&levels=Elem">Elem</option>'; } if ($_GET[levels] == 'MS') { echo '<option selected value="'; ?> <?php echo "$page_name" ?> <?php echo '&start=0&levels=MS">MS</option>'; } else { echo '<option value="'; ?> <?php echo "$page_name" ?> <?php echo '&levels=MS">MS</option>'; } if ($_GET[levels] == 'HS') { echo '<option selected value="'; ?> <?php echo "$page_name" ?> <?php echo '&start=0&levels=HS">HS</option>'; } else { echo '<option value="'; ?> <?php echo "$page_name" ?> <?php echo '&levels=HS">HS</option>'; } if ($_GET[levels] == 'College') { echo '<option selected value="'; ?> <?php echo "$page_name" ?> <?php echo '&start=0&levels=College">College</option>'; } else { echo '<option value="'; ?> <?php echo "$page_name" ?> <?php echo '&levels=College">College</option>'; } if ($_GET[levels] == 'Prvt') { echo '<option selected value="'; ?> <?php echo "$page_name" ?> <?php echo '&start=0&levels=Prvt">Prvt</option>'; } else { echo '<option value="'; ?> <?php echo "$page_name" ?> <?php echo '&levels=Prvt">Prvt</option>'; } if ($_GET[levels] == 'Admin') { echo '<option selected value="'; ?> <?php echo "$page_name" ?> <?php echo '&start=0&levels=Admin">Admin</option>'; } else { echo '<option value="'; ?> <?php echo "$page_name" ?> <?php echo '&levels=Admin">Admin</option>'; } echo ' </select> </form>'; ?> Now, I'm keeping all those terms as separate variables, and combining them in an array. (I think that's right.) Code: [Select] $PreK = $PreK; $Elem = $Elem; $MS = $MS; $HS = $HS; $College = $College; $Admin = $Admin; $Prvt = $Prvt; $levels = array($PreK, $Elem, $MS, $HS, $College, $Admin, $Prvt); foreach ($levels as $key => $v ) if (!$v) unset ($levels[$key]); $levels = implode(', ', $levels); echo $levels; My question, how do I modify my pulldown form (above) to check the WHOLE array for these values? I'm so lost... Thanks. ~Wayne Hello, I am a PHP biginner. I would be grateful if you could help with the issue below. I have created three input dynamic variables in a separate php file using a For lopp.
<?php
The form works well. In another PHP I would like to use the three arrays workday[], startTime[] and endTime to calculate the duration between startTime and endTime for each working day. I can access the different arrays using Foreach like below but I don't see how to combine thos arrays in order to be able to calculate the duration between two data that are in diffrent arrays. Is it possible to make calculations using variables stored in different arrays ? If so could you help me understand how ?
<?php
if (isset($_POST['workday'])) { echo $workday . "<br>;
}
echo $startTime. "<br>;
if (isset($_POST['endTime'])) {
echo $endTime. "<br>;
Hi I have a page that the user selects a category and I have the page sending a variable to a page. However, I want the user to be able to select multiple options and therefore need the page doing the query to build an array and change the search results accordingly! Please can someonehelp me with what I have as I am jsut NOT getting my head around this! Here is the 'form' info Code: [Select] <input name="jqdemo" value="6" type="checkbox" id="party"/> <label for="party"></label> <a class="checkbox-select" href="# id="6" onclick="showUser(this.id)""><img src="Assets/images/blank.png" alt="" width="120" height="180" /></a> <a class="checkbox-deselect" href="#" id="0" onclick="showUser(this.id)"><img src="Assets/images/blank.png" alt="" width="120" height="180" /></a> Then this is the page that is doing the query Code: [Select] <?php $q=$_GET["q"]; $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db_pyf", $con); //$sql="SELECT * FROM tbl_product WHERE cat_id IN '".$q."'"; $sql="SELECT * FROM tbl_product WHERE cat_id IN (3,1,2)"; $result = mysql_query($sql); echo "<table border='1'> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> <th>Hometown</th> <th>Job</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['prod_name'] . "</td>"; echo "<td>" . $row['prod_desc1'] . "</td>"; echo "<td>" . $row['member_id'] . "</td>"; echo "<td>" . $row['cat_id'] . "</td>"; echo "<td>" . $row['cat_id'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> But, as I have said, I want the user to be able to select multiple options and want the search to adjust accordingly! Hello, I've created a function whereby I want to return the school_id associated with a particular user. Each user will be associated with exactly one school. My query below works, but the thing that it returns is an array; I need to make use of it as a variable (say $instructor_school_id). Any idea how to make the conversion from a single element array into a non-array variable? Thank you.... function getInstructorSchool($read, $user_id) { $sql = "SELECT school_id FROM users WHERE user_id = $user_id"; return $read->fetchRow($sql); } I have the following loop in which I receive Parse error: $letters = array ("A", "B", "C", "D","E", "F", "G", "H","I", "J", "K", "L", "M", "N", "O", "P","Q", "R", "S", "T","U", "V", "W", "X", "Y", "Z", "Æ", "Ø", "Å"); for ($i = 1; $i < 29; $i++) { if ($_POST['$letters['$i']']){ echo "You have selected the following products:" . "<br>" . $_POST['$letters['$i']]; } } or is it possible to write something like that: for ($i = 1; $i < 300; $i++) { if ($_POST['$i']){ echo "You have selected the following products:" . "<br>" . $_POST['$i']; } } Please, help me. I need to use array and variables inside _POST[]. Okay I have a function that stores data into an Array. The function takes about 7 seconds to run and through a number of different loops it creates one final array with about 15,000 keys. I want to recall this data a number of times in different functions, however how can I have this data easily accessible without running the function each time. EX: Code: [Select] function theFunction() { for($x=0;$x,=15000;$x++) { //Run the loop and store data. $string[$x] = //output from other loops and calculations } return $string } //Then later on if I want to recall the data the only way I know how is to do the follow: $newstring = theFunction() The only problem I have with this is that it has to re-run the function every time in order to get to the data it spits out. How can I store this data into another array outside of the function without having to re-run it? I hope this makes sense. Thanks. I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? does anyone know how to decode this XML variable value into string values? I also need to know the oposite way: creating variable values into xml. I've tried several code examples but they did filter the requested data. Code: [Select] $xml='<?xml version="1.0" encoding="utf-8"?> <elements> <text identifier="ed9cdd4c-ae8b-4ecb-bca7-e12a5153bc02"> <value/> </text> <textarea identifier="a77f06fc-1561-453c-a429-8dd05cdc29f5"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <textarea identifier="1a85a7a6-2aba-4480-925b-6b97d311ee6c"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <image identifier="ffcc1c50-8dbd-4115-b463-b43bdcd44a57"> <file><![CDATA[images/stories/red/cars/autobedrijf.png]]></file> <title/> <link/> <target/> <rel/> <lightbox_image/> <width><![CDATA[250]]></width> <height><![CDATA[187]]></height> </image> <text identifier="4339a108-f907-4661-9aab-d6f3f00e736e"> <value><![CDATA[Kramer 5]]></value> </text> <text identifier="ea0666d7-51e3-4e52-8617-25e3ad61f8b8"> <value><![CDATA[6000 RS]]></value> </text> <text identifier="90a18889-884b-4d53-a302-4e6e4595efa0"> <value><![CDATA[Eindhoven]]></value> </text> <text identifier="410d72e0-29b3-4a92-b7d7-f01e828b1586"> <value><![CDATA[APK Pick up and return]]></value> </text> <text identifier="45b86f23-e656-4a81-bb8f-84e5ea76f71f"> <value><![CDATA[15% korting op grote beurt]]></value> </text> <text identifier="3dbbe1c6-15d6-4375-9f2f-f0e7287e29f3"> <value><![CDATA[Gratis opslag zomerbanden]]></value> </text> <text identifier="2e878db0-605d-4d58-9806-8e75bced67a4"> <value><![CDATA[Gratis abonnement of grote beurt]]></value> </text> <text identifier="94e3e08f-e008-487b-9cbd-25d108a9705e"> <value/> </text> <text identifier="73e74b73-f509-4de7-91cf-e919d14bdb0b"> <value/> </text> <text identifier="b870164b-fe78-45b0-b840-8ebceb9b9cb6"> <value><![CDATA[040 123 45 67]]></value> </text> <text identifier="8a91aab2-7862-4a04-bd28-07f1ff4acce5"> <value/> </text> <email identifier="3f15b5e4-0dea-4114-a870-1106b85248de"> <value/> <text/> <subject/> <body/> </email> <link identifier="0b3d983e-b2fa-4728-afa0-a0b640fa34dc"> <value/> <text/> <target/> <custom_title/> <rel/> </link> <relateditems identifier="7056f1d2-5253-40b6-8efd-d289b10a8c69"/> <rating identifier="cf6dd846-5774-47aa-8ca7-c1623c06e130"> <votes><![CDATA[1]]></votes> <value><![CDATA[1.0000]]></value> </rating> <googlemaps identifier="160bd40a-3e0e-48de-b6cd-56cdcc9db892"> <location><![CDATA[50.895711,5.955427]]></location> </googlemaps> </elements>'; Hi. I have some code which needs to return a single variable from the function and stored as a variable within this page, so it can be echoed later on in the page. I couldn't get it to return as a variable, so i used "return compact();" to return the variable and "extract (myFunction());" to extract it to variables. However, when I turned on php's display errors and error reporting function, I got an error message saying "Warning: extract() [function.extract]: First argument should be an array in /my/web/site/index.php on line 6" (which is where my extract function is). This works fine with passing more than one variables through, is there another way pass one variable from a function to be stored as a variable on the page which called the function? Here is the function: Code: [Select] <?php //This is a list of numeric error codes against their text. this will return the error code as the variable $issue function checkLoginIssue() { //If there is an error code if (isset($_GET["issue"])) { //cycle through the list until the code is reached, return the text and break the switch switch ($_GET["issue"]) { case "1": $issue = '<p class="warning">Please log in to view this page</p>'; break; case "2": $issue = '<p class="warning">Wrong Username or Password</p>'; break; case "3": $issue = '<p class="warning">No user found with those details</p>'; break; } //return the variable in an array with a single value return compact('issue'); } } ?> And here is the code which calls the function: Code: [Select] <?php extract(checkLoginIssue()); ?> hi all, how can i make this array dynamic. E.g, i want the numbers to be pulled from a database... Code: [Select] $s=array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" ); thanks in advance, i just cant work it out Ok so this link returns HTML $hitlist = file_get_contents($iMobLink."get_hit_list?user_id=".$iStore[2]."&level=10&auth_key=".$iStore[3]); now to parse it out I have this $entry = explode('<entry>', $hitlist); $hitlist = file_get_contents($iMobLink."get_hit_list?user_id=".$iStore[2]."&level=10&auth_key=".$iStore[3]); $user_id = explode('<user_id>', $hitlist); $user_id = explode('</user_id>', $user_id[1]); $mobname = explode('<mob_name>', $hitlist); $mobname = explode('</mob_name>', $mobname[1]); $paiduser = explode('<paid_user>', $hitlist); $paiduser = explode('</paid_user>', $paid_user[1]); $amount = explode('<amount>', $hitlist); $amount = explode('</amount>', $amount[1]); $paid_time = explode('<placed_time_ago>', $hitlist); $paid_time = explode('</placed_time_ago>', $paid_time[1]); $level = explode('<level>', $hitlist); $level = explode('</level>', $level[1]); $entry = explode('</entry>', $entry[1]); echo $user_id[0]."\n"; echo urldecode($mobname[0])."\n"; echo $amount[0]."\n"; echo $paid_time[0]."\n"; echo $level[0]."\n"; echo $entry[0];} Ok now.... this only returns one entry of the xml when there are more than 10. I need it to return all ten+ of the entrys here is what the xml looks like <outer> − <xml> − <entry> − <target_user> <user_id>512433892</user_id> <mob_name>MR%2025TATT00S%2C%20Level%2015</mob_name> </target_user> − <paid_user> <user_id>554190549</user_id> <mob_name>PRINCE%20OF%20NEW</mob_name> </paid_user> <amount>48000000000</amount> <is_npc>false</is_npc> <placed_time_ago>3 days ago</placed_time_ago> <level>15</level> </entry> − <entry> − <target_user> <user_id>530120192</user_id> <mob_name>EVILNESS%20SIMPLIFIED%2C%20Level%2013</mob_name> </target_user> − <paid_user> <user_id>539494114</user_id> <mob_name>StompinDatAzz</mob_name> </paid_user> <amount>1478608800</amount> <is_npc>false</is_npc> <placed_time_ago>1 day ago</placed_time_ago> <level>13</level> </entry> − <entry> − <target_user> <user_id>526183645</user_id> <mob_name>snatch%20rider%2C%20Level%20112</mob_name> </target_user> − <paid_user> <user_id>450207248</user_id> <mob_name>ShiftyShellShock</mob_name> </paid_user> <amount>999999999</amount> <is_npc>false</is_npc> <placed_time_ago>22 hours ago</placed_time_ago> <level>112</level> </entry> − <entry> − <target_user> <user_id>542145086</user_id> <mob_name>Riding%20Raider%2C%20Level%2043</mob_name> </target_user> − <paid_user> <user_id>513441119</user_id> <mob_name>Level%20U%20uP</mob_name> </paid_user> <amount>334616000</amount> <is_npc>false</is_npc> <placed_time_ago>18 hours ago</placed_time_ago> <level>43</level> </entry> − <entry> − <target_user> <user_id>554043828</user_id> <mob_name>klaibers%20limited%2C%20Level%2011</mob_name> </target_user> − <paid_user> <user_id>522432052</user_id> <mob_name>Sloppy%20Seconds</mob_name> </paid_user> <amount>39344504405</amount> <is_npc>false</is_npc> <placed_time_ago>17 hours ago</placed_time_ago> <level>11</level> </entry> − <entry> − <target_user> <user_id>496266215</user_id> <mob_name>Geheim%20Abwher%2C%20Level%207</mob_name> </target_user> − <paid_user> <user_id>216904061</user_id> <mob_name>yve1</mob_name> </paid_user> <amount>2499912800</amount> <is_npc>false</is_npc> <placed_time_ago>16 hours ago</placed_time_ago> <level>7</level> </entry> − <entry> − <target_user> <user_id>524874924</user_id> <mob_name>MYLILFRIEND%2C%20Level%20104</mob_name> </target_user> − <paid_user> <user_id>536745842</user_id> <mob_name>SUC%20MY%20GLOCK</mob_name> </paid_user> <amount>1615247200</amount> <is_npc>false</is_npc> <placed_time_ago>15 hours ago</placed_time_ago> <level>104</level> </entry> − <entry> − <target_user> <user_id>531185082</user_id> <mob_name>THE%20RAGE%20WITHIN%2C%20Level%2031</mob_name> </target_user> − <paid_user> <user_id>512862859</user_id> <mob_name>The%20Kozmik%20Slop</mob_name> </paid_user> <amount>16536800</amount> <is_npc>false</is_npc> <placed_time_ago>14 hours ago</placed_time_ago> <level>31</level> </entry> − <entry> − <target_user> <user_id>494326270</user_id> <mob_name>RIDE%20HIS%20CUCUMBER%2C%20Level%2016</mob_name> </target_user> − <paid_user> <user_id>554794332</user_id> <mob_name>STDS%20R%20BAD%20MMKAY</mob_name> </paid_user> <amount>337825600</amount> <is_npc>false</is_npc> <placed_time_ago>14 hours ago</placed_time_ago> <level>16</level> </entry> − <entry> − <target_user> <user_id>558355598</user_id> <mob_name>DEATH%20TO%20HITLIST%2C%20Level%2011</mob_name> </target_user> − <paid_user> <user_id>558349535</user_id> <mob_name>Gangsta%20Love</mob_name> </paid_user> <amount>181600000</amount> <is_npc>false</is_npc> <placed_time_ago>10 hours ago</placed_time_ago> <level>11</level> </entry> − <entry> − <target_user> <user_id>545114043</user_id> <mob_name>Ridin%20Dirty%2C%20Level%20130</mob_name> </target_user> − <paid_user> <user_id>510805692</user_id> <mob_name>iced%20baby</mob_name> </paid_user> <amount>481680800</amount> <is_npc>false</is_npc> <placed_time_ago>10 hours ago</placed_time_ago> <level>130</level> </entry> Notice there is more than one energy.. now how to I parse it out to where I can define each entry by a variable or something... any help is appreciated.. Thanks Hi Guys, I have an array Code: [Select] $arr When i run this function Code: [Select] print_r($arr) I get the output below:- -------------------------------- Code: [Select] Array ( [WHMCSAPI] => Array ( [ACTION] => getclientsproducts [RESULT] => success [CLIENTID] => 87 [PID] => 13 [DOMAIN] => dfgbhcgnd.com [TOTALRESULTS] => 1 [STARTNUMBER] => 0 [NUMRETURNED] => 1 [PRODUCTS] => Array ( [PRODUCT] => Array ( [ID] => 196 [CLIENTID] => 87 [ORDERID] => 218 [PID] => 13 [REGDATE] => 2011-12-07 [NAME] => Walderizer [DOMAIN] => dfgbhcgnd.com [DEDICATEDIP] => [SERVERID] => 3 [FIRSTPAYMENTAMOUNT] => 55.00 [RECURRINGAMOUNT] => 55.00 [PAYMENTMETHOD] => banktransfer [PAYMENTMETHODNAME] => Bank Transfer [BILLINGCYCLE] => Monthly [NEXTDUEDATE] => 2011-12-07 [STATUS] => Active [USERNAME] => vitaforiz [PASSWORD] => ghTfg476fg [SUBSCRIPTIONID] => [LASTUPDATE] => 0000-00-00 00:00:00 [CUSTOMFIELDS] => Array ( [CUSTOMFIELD] => Array ( [NAME] => IP Address [VALUE] => ) ) [CONFIGOPTIONS] => ) ) ) ) --------------------------------- My question is, how can i print only certain parts of the data rather than printing the whole array. For example i only want to echo the values for [NAME], [USERNAME], [PASSWORD] and [NEXTDUEDATE] from the [PRODUCT] part of the array Thanks in advance I have ticket's for my lottery system. Somone chooses 3 random numbers out of 36, it will show 1|20|30 but now I want to beable to have my Members BUY multiple Tickets! So then I added a comma between the 3 arrays So the code will look like this when they select the balls they want Code: [Select] 1|20|30,20|10|5 /etc /etc But now I have 1 problem. How do I go about validating the arrays for each COMMA inside the | ARRAY? Cause let's saY I don't want anyone to Submit a ball number higher then "36" how would I go about making it so it checks through each array and if it's higher then 32 I can give them a Error? Also, I each Ticket costs (5 Forum Gold) so the above code would be a total of 10 Forum Gold, because they're "2" Tickets being bought, how would I go about making a $counter++ in the arrays to count only the "," so I can tell how much Gold the member needs to have before he purchases Thanks I have some similar arrays. How I can combine them to shuffle the new array? Arrays in C are fixed length:
#define MAX_SIZE 5 int main(void){ int n[ 5 ]; for(int i=0;i<MAX_SIZE;i++){ n[i]=i; } return 1; }If I try to insert an eleement into the array, it will result in undefined behavior. Java compensates for this by creating an actual object class called ArrayList or LinkedList, the former an internal store of array elements that dynamically resizes and the latter just a node tree with pointers to next and previous elements. ArrayList<Integer> arr = new ArrayList<Integer>(); arr.add(1); arr.add(2);It seens that the array() construct in PHP is not a function or a class but an internal construct. How does it dynamically resize arrays? Hello! i want to store data in a array (as seen in the code). Im trying to make it so that a php code search through the arrays and find the correct one. once it does it tells me. I dont know if im close, How ever this is what i have. $carrier = $_POST['carrier']; $carriers = array( array("verizon","tmobile","sprint","att","virgin","textnow","metro","unknown"), array("@vtext.com","@tomomail.net","@messaging.sprintpcs.com","@txt.att.net","@vmobl.com","@textnow.me","@mymetropcs.com","@teleflip.com") ); If ($carrier = I have created two classes. One is called 'move' and the other 'unit'. To make my example easier to follow, I shall use the much loved pokemon series to explain my dilemma. Here are the class declarations. new class unit { var $name, $moves; public function newUnit($name, $moves) { $this->name = $name; $this->moves = $moves; } } new class move { var $name, $attack; public function newMove($name, $attack) { $this->name = $name; $this->moves = $moves; } } Now I shall instantiate these classes (if that makes sense xD) - I just started OOP yesterday, do mind my ignorance. $unit = array(); $move = array(); $unit[0] = new unit; $unit[0]->newUnit("picachu",array("thunderbolt","quick-attack")); Now, let's say I want to populate the $move array with the moves in the unit object (thunderbolt and quick-attack). I can retrieve their attack values from a database: $thunderboltAttack = 200; $quick-attackAttack = 40; I now want to create a function that will create instances of the 'move' class to produce: $move[0] = new move; $move[0]->newMove("thunderbolt",200); $move[1] = new move; $move[1]->newMove("quick-attack",40); Here is my dire attempt to do so: function createUnits($moves){ //$moves is the array holding the unit's moves for($i; $i < count($moves); $i++) { $arr[] =new move; $arr[count($units) - 1]->name = $moves[0]; $arr[count($units) - 1]->attack = $someAttackData; } return $arr; } $moves[] = createUnits; I'm ending up with a multi-dimensional array when I want a linear one like this: $move[0] = new move; $move[0]->newMove("thunderbolt",200); $move[1] = new move; $move[1]->newMove("quick-attack",40); What do I need to do. Do I have to resort to making $move global from within the function and do things that way? Hello, I have 2 array questions that I'm hoping someone can help me with. 1) First, I'm trying to add elements to a previously existing array. I start with: $data = array('text' => $_POST['text'], 'question_type' => $_POST['question_type'], 'solution' => $_POST['solution'], 'filename' => $filename, 'author_id' => $_POST['author']); Then, under certain circumstances, I'm going to want to add the following to the array $data: 'incorrect_solution1' => $_POST['incorrect_solution1'], 'incorrect_solution2' => $_POST['incorrect_solution2'], 'incorrect_solution3' => $_POST['incorrect_solution3']) I tried the concatenation function, combined with an if statement but then PHP thinks that I have a string. 2) Once I have the array, I want to shuffle the solution and 3 incorrect solution indices. I'm not sure how to shuffle just a portion of an array. Any help with either or both questions would be appreciated. Thank you. |