PHP - Please Help Me With Json And Php Multi-dimentional Array
Hi,
I have been banging my head against a brick wall the past few days trying to figure this out after reading so many tutorial and forum post but I still can't figure it out. I would be very grateful if someone could help me out. Basically I am being supplied with this JSON Data structu $json='{ "countries": { "country": [ { "@attributes": { "Name": "Germany", "Lat": "52.6847077739394", "Lng": "-6.81976318359375", "ZoomLevel": "7" } }, { "@attributes": { "Name": "Sweeden", "Lat": "54.00131186464818", "Lng": "-7.36358642578125", "ZoomLevel": "8" } } ] } }'; I decode the JSON data structure as a PHP array and I print out the contents of the array for debugging purposes: $json_array=json_decode($json,true); print_r($json_array); Heres what the outputed array looks like: Code: [Select] Array ( [countries] => Array ( [country] => Array ( [0] => Array ( [@attributes] => Array ( [Name] => Germany [Lat] => 52.6847077739394 [Lng] => -6.81976318359375 [ZoomLevel] => 7 ) ) [1] => Array ( [@attributes] => Array ( [Name] => Sweeden [Lat] => 54.00131186464818 [Lng] => -7.36358642578125 [ZoomLevel] => 8 ) ) ) ) ) I want to be able to access all the country names contained in [Name] Can anyone please help me on how to do this correctly as I've tried lots of code with multi-dimensional arrays but I've had no luck. I am not able to acces the variable correctly. Thanks in advance. Similar TutorialsHi can anybody help me out with the following problem I am having? I need to populate the key values in the multi-dimentional array structure shown below and the values will be used later in the following way: <tr> <td><?php echo $sm_array[1]['col_1']; ?></td> <td><?php echo $sm_array[1]['col_2']; ?></td> <td><?php echo $sm_array[1]['col_3']; ?></td> <td><?php echo $sm_array[1]['col_4']; ?></td> //and so on, up to 10 </tr> <tr> <td><?php echo $sm_array[2]['col_1']; ?></td> <td><?php echo $sm_array[2]['col_2']; ?></td> <td><?php echo $sm_array[2]['col_3']; ?></td> <td><?php echo $sm_array[2]['col_4']; ?></td> //and so on, up to 10 </tr> This is the array structure, $td->innertext is just a different value each time and is not important for this example, it could essentially be anything: sm_array[$row] = array( "col_1" => $td->innertext, "col_2" => $td->innertext, "col_3" => $td->innertext, "col_4" => $td->innertext, "col_5" => $td->innertext, "col_6" => $td->innertext, "col_7" => $td->innertext, "col_8" => $td->innertext, "col_9" => $td->innertext, "col_10" => $td->innertext, ); But I need to add the values inside a loop, like this: while($row=0; $row<=10; $row++) { $sm_array[$row] = array( "col_".$row => $td->innertext); } But this doesn't allow me to change the key name inside the loop, so for $sm_array[1] there will be 10 keys and their values, and the same for $sm_array[2], it will also have 10 keys and different values for each key and so on! But for some reason the key value will not work this way inside a loop, it doesn't allow "col_".$row and I even tried to echo the key name, like this: while($row=0; $row<=10; $row++) { $sm_array[$row] = array( "<?php echo $row; ?>" => $td->innertext); } It only seems to accept a fixed string or integer as the key, like this: while($row=0; $row<=10; $row++) { $sm_array[$row] = array( "col_1" => $td->innertext); // or like this $sm_array[$row] = array( 1 => $td->innertext); } But then I have a problem, I can't change the key name dynamically! I have tried doing this with conditional staments like this, but it only accepts the first key name and the 2nd, 3rd etc, etc all fail: while($row=0; $row<=10; $row++) { if($row==1){ $sm_array[$row] = array( "col_1" => $td->innertext); }else if($row==2){ $sm_array[$row] = array( "col_2" => $td->innertext); } //and so on } Can somebody please tell me what I am doing wrong or can't this be done or is their some other way of doing this? Thanks in advance Grant Hi Guys, I have got a large nested multi dimensional array, I have the following function that nearly does what I want: This is the array: Array ( [country] => Scotland .... I run it through the function below, and it finds all the nested keys and the output is Array ( [0] => country [1] .... All the keys are represented but the values are not set, how can I get the function to add the value? function array_keys_multi(array $array){ $keys = array(); foreach ($array as $key => $value) { $keys[] = $key; if (is_array($array[$key])) { $keys = array_merge($keys, array_keys_multi($array[$key])); "<br>"; } } return $keys;... } Hi, sorry if this has been covered elsewhere but I'm stuck. I'm trying to output individual headers when converted from json into an array. The array contains 6 headers eg. description, url etc but my result looks like the json_decode isn't working. The raw data looks fine when I output from print_r on the page. The code looks like this: -------------------------------------------------------------------- $json_array = json_decode($json,true); //print_r ($json_array); foreach ($json_array as $row) { echo $row["description"]." = ".$row["url"]."<br />"; ---------------------------------------------------------------------- the result is: ----------------------------------------------------------------------- C = C h = h = 0 = 0 c = c C = C ----------------------------------------------------------------------- Can anyone help or point me to a tutorial I can work though. Thanks Jogga Hello all, I have yet again trouble finding a logical solution to my problem. I'm fetching an array which can hold 1 or more values. The problem is, I want these values to ouput in my json_encode function, but this also needs to happen dynamically depending on the amount of values. I can't explain it further, so here's the code so far: Code: (php) [Select] $files = mysql_fetch_array($get_files); $a = count($files); $i = 1; while ($files) { $variablename = 'fileName' . $i; $$variablename = $files['fileName']; $i++; } $output = array( OTHER VALUES , 'fileName1' => $fileName1, 'fileName2' => $fileName2, 'fileName3' => $fileName3, ............); // How do I add the fileNames dynamically depending on how many there are? This got me thinking, I also need to dynamically GET the values with jQuery. How would I do that, when the above eventually works? Thank you. I have a for loop which extracts info from a MySQL table, chooses something then needs to push each bit into an array: for($i = 0 ; $i < $query_report_rows ; ++$i) { $row= mysql_fetch_row($query_names); if($row[6] == 0) { $sName = $row[1]; } elseif($row[6] == 1) { $sName = $row[2]; } $name = "$row[0], $sName"; $print = nl2br($row[7]); } What i need is a multidimensional array to hold $name and $print: $name_print = array( array('name'=>$name 'print'=>$print ) ) How do i array push into such an array from the above for loop? (multi-dimensional array are a very weak point at the moment, so any pointers here would be very much appreciated) I have a json file returned by facebook e.g { "data": [ { "name": "Support! Muffin the fool (Oldham Chronicle FAKE)", "category": "Community", "id": "181377645219010", "access_token": "102650199811234|060d3610d4dba63953209fa5-637782927|181377645219010|MvOBJKYtO7eT8JxMLtJ00HtGNxo" }, { "name": "Northplanet", "category": "Local business", "id": "132483460132622", "access_token": "102650199811234|060d3610d4dba63953209fa5-637782927|132483460132622|AHXPNTZx7aihyQS_A9W6pR115U4" }, { "name": "Social Media Manger", "category": "Application", "id": "102650199811234", "access_token": "102650199811234|060d3610d4dba63953209fa5-637782927|102650199811234|KeH0n1OKzZFtCkpa0lX1yJZ7NBE" }, { "name": "Top Ten Things To Remember Me By!", "category": "Application", "id": "375102030458", "access_token": "102650199811234|060d3610d4dba63953209fa5-637782927|375102030458|H-mpQWrksu_2FzZ_eBNVzeD2Z1Y" } ] } $graph_url = "https://graph.facebook.com/$uid/comments=" . $access_token; $api = json_decode(file_get_contents($graph_url)); $name = $api->data->name; // this bit not storing the name not sure why I am writing a simple connector for an android application and my json_encode is outputting enclosing the array with []. This is throwing an error during the decode process because the array needs to start with a {. I know this has to do with the $output[] in the loop, but I dont know how to pass the values into the array any other way. I even tried to trim after doing the encode. Here is my code: Code: [Select] <?php require_once ('includes/config.php'); require_once ('includes/connect.php'); $agency= mysql_query("SELECT agencyname FROM agency WHERE status ='Prospect' ORDER BY agencyname DESC")or die(mysql_error()); while($ageinfo = mysql_fetch_assoc($agency)) { $output[] = $ageinfo; } print(json_encode($output)); ?> Hello everyone. I'm a self learner that is very new to programming. I'm trying to print out the value of ["mid"] from a json_decode variable in the code shown below: I'm trying to use for each to access the value of "mid'. using foreach function. I know I'm not doing it the right way. please help me or show me an easy was to go around it. /////the json resopnd form the url is : {"terms":"http://www.xe.com/legal/dfs.php","privacy":"http://www.xe.com/privacy.php","from":"USD","amount":1.195,"timestamp":"2021-02-09T16:52:00Z","to":[{"quotecurrency":"NGN","mid":454.6559871014}]} ///////////////////////////////////////////////// <?php $auth = base64_encode("username:password"); $context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ] ]); $homepage = file_get_contents("https://xecdapi.xe.com/v1/convert_from?to=NGN&amount=1.195", false, $context ); $json = json_decode($homepage, TRUE); foreach ($json as $price){ echo $price['mid']; }; ?>
i am brand new to php and thought a project looking at the weather undergound api would be a great place to "cut my teeth" and i am following up on a recent post i saw here http://www.phpfreaks.com/forums/index.php?topic=354658.msg1675207#msg1675207 the responder excellently described how to use the foreach function however i am not sure this is right for my application the project i am trying to accomplish is defining the freeze thaw cycle for the next ten days which i can accomplish in excel but thought this is a good way to learn to code. so my question is how should i do this, i have tried and failed with trying to pick out individual highs and lows data and define them as above or below freezing but i can't figure out how to pick out the right number my code for this part of the project is $json_line = file_get_contents("http://api.wunderground.com/api/{key}/geolookup/forecast10day/q/$zipcode.json"); $parsed_line = json_decode($json_line); echo $parsed_json->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'date'}->{'weekday'}; $temp_h = $parsed_line->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'high'}->{'farenheit'}; $temp_l = $parsed_json->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'low'}->{'farenheit'}; echo "Forecast for ${day} is:\n"; echo "High Temp is ${temp_h}<br />"; echo "Low Temp is ${temp_l}\n"; another road i was looking at going down was trying to do an array shift any help would be greatly appreciated thanks jeremy Havent posted here in a while, been learning lots but im stuck on trying to unset/replace arrays that contain awkward key values.
[0] => 2021-06-02T19:40:00Z [1] => 2021-06-03T02:10:00Z [2] => 2021-06-03T01:10:00Z [3] => 2021-06-02T23:05:00Z [4] => 2021-06-02T23:05:00Z [5] => 2021-06-02T23:07:00Z [6] => 2021-06-02T23:20:00Z [7] => 2021-06-02T18:20:00Z [8] => 2021-06-03T00:10:00Z [9] => 2021-06-03T00:40:00Z The json Im using is constantly updated, not sure why tmrw's dates June 3rd are at the top for their API design =[ Not good at regex. preg_replace/etc. Im desperate id use array search manually if I knew how to simple parse out tmrw's dates. I have unlimited API calls so I reckon it don't matter, here's what Ive been playing with $oddsdata = 'https://pinnacle.datafeeds.net/api/json/odds/pinnacle/v3/60/baseball/mlb/moneyline?api-key=a71b8fe8e9eb957db549aaa5d99797a4'; $readodds = file_get_contents($oddsdata); $odds = json_decode($readodds, true); $today = date("Y-m-d"); $tmrw = date('Y-m-d', strtotime( $today . " +1 days")); foreach($odds['games'] as $key => $val): $gidRE[$key]["gid"] = $val["gameUID"]; $startOdds[$key]["start"] = $val["startDate"]; $homeTeams[$key]["hteam"] = $val["homeTeam"]; $awayTeams[$key]["ateam"] = $val["awayTeam"]; $Price[$key]["betPrice"] = $val["betPrice"]; $BookOdds[$key]["book"] = $val["sportsbook"]; $BetName[$key]["betName"] = $val["betName"]; $Live[$key]["Live"] = $val["isLive"]; endforeach; $endgidd = end(array_keys($gidRE)) + '1'; $endz = end(array_keys($odds['games'])); for ($l = 0; $l < $endz; ++$l) { $OddsAll[] = array_merge($gidRE[$l], $startOdds[$l], $homeTeams[$l], $awayTeams[$l], $Price[$l], $BetName[$l]); }
<?php ini_set('display_errors', 0); function escapeArray($array) { foreach ($array as $key => $val) { if(is_array($val)){ $array[$key]=escapeArray($val); } else{ $array[$key]=addslashes($val); } } return $array; } $request_type=$_SERVER['REQUEST_METHOD']; $api_key=$_SERVER['HTTP_X_API_KEY']; $res=array(); if($api_key!=="643256432"){ $res['msg']="Failu Invalid API KEY"; echo json_encode($res); die; } // Connects to the orcl service (i.e. database) on the "localhost" machine //$conn = oci_connect('SCOTT', 'admin123', 'localhost/orcl'); $conn = oci_connect('test', 'test', '192.168.10.43/test.test.com'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $request=file_get_contents("php://input"); $request=escapeArray(json_decode($request,true)); print_r($request); // die; if($request_type=="POST"){//for creation of invoice echo $CONTACT_ID=isset($request['CONTACT_ID'])?$request['CONTACT_ID']:""; $INV_SERIAL_NO=isset($request['INV_SERIAL_NO'])?$request['INV_SERIAL_NO']:""; $NAME=isset($request['NAME'])?$request['NAME']:""; $INV_DATE=isset($request['INV_DATE'])?$request['INV_DATE']:""; $DUE_DATE=isset($request['DUE_DATE'])?$request['DUE_DATE']:""; $CURRENCY=isset($request['CURRENCY'])?$request['CURRENCY']:""; $SUBTOTAL=isset($request['SUBTOTAL'])?$request['SUBTOTAL']:""; $TAX_TOTAL=isset($request['TAX_TOTAL'])?$request['TAX_TOTAL']:""; echo $SHIP_SERIAL_NO=isset($request['SHIP_SERIAL_NO'])?$request['SHIP_SERIAL_NO']:""; $MASTER_NO=isset($request['MASTER_NO'])?$request['MASTER_NO']:""; $HOUSE_NO=isset($request['HOUSE_NO'])?$request['HOUSE_NO']:""; $shipment_data=isset($request['shipment_data'])?$request['shipment_data']:""; if($CONTACT_ID==""){ $res['msg']="CONTACT_ID is required"; } else if($INV_SERIAL_NO==""){ $res['msg']="INV_SERIAL_NO is required"; } else if($NAME==""){ $res['msg']="NAME is required"; } else if($INV_DATE==""){ $res['msg']="INV_DATE is required"; } else if($DUE_DATE==""){ $res['msg']="DUE_DATE is required"; } else if($CURRENCY==""){ $res['msg']="CURRENCY is required"; } else if($SUBTOTAL==""){ $res['msg']="SUBTOTAL is required"; } else if($TAX_TOTAL==""){ $res['msg']="TAX_TOTAL is required"; } else if($MASTER_NO==""){ $res['msg']="MASTER_NO is required"; } else if($HOUSE_NO==""){ $res['msg']="HOUSE_NO is required"; } else if($SHIP_SERIAL_NO==""){ $res['msg']="SHIP_SERIAL_NO is required"; } else{ $stid = oci_parse($conn, "Select * from FL_HDR_INVOICE where CONTACT_ID='$CONTACT_ID'"); (oci_execute($stid)); oci_fetch_all($stid, $out); if(count($out['CONTACT_ID'])==0){ $stid = oci_parse($conn, "Insert into FL_HDR_INVOICE (CONTACT_ID,INV_SERIAL_NO,NAME,INV_DATE,DUE_DATE,CURRENCY,SUBTOTAL,TAX_TOTAL) Values ('$CONTACT_ID','$INV_SERIAL_NO','$NAME',TO_DATE('$INV_DATE','YYYY-MM-DD'),TO_DATE('$DUE_DATE','YYYY-MM-DD'),'$CURRENCY','$SUBTOTAL','$TAX_TOTAL')"); oci_execute($stid); $stid_2 = oci_parse($conn, "Insert into FL_SHIPMENT_DATA (CONTACT_ID,INV_SERIAL_NO,SHIP_SERIAL_NO,MASTER_NO,HOUSE_NO) Values ('$CONTACT_ID','$INV_SERIAL_NO','$SHIP_SERIAL_NO','$MASTER_NO','$HOUSE_NO')"); oci_execute($stid_2); if(oci_num_rows($stid)>0){ $res['msg']="Invoice created successfully against this contact_id:".$CONTACT_ID; } else{ $res['msg']="Something going wrong please try again later"; } } else{ $res['msg']="contact_id must be unique"; } } echo json_encode($res); die; } I need to read json data inside an array. Please help correct my code.. i am trying to do an API. Hi, I have the following code that takes a list from a mySQL db and puts it into an array that shows 'gig date, venue, city' per entry: - Code: [Select] while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $array[] = ($row['date'].', '.$row['gl_venue'].', '.$row['gl_city']); } $output = json_encode($array); this outputs JSON like so: Code: [Select] ["06-05-2011, O'neills, Southend","07-05-2011, Power League, Peterborough","14-05-2011, Queen Victoria hall, Oundle",.......] how do I add keys into the array so I get something like: Code: [Select] {"gigs":[ { "gig": "date, venue, city",} ]} at least I think so anyway!?! What I want to do is eventually be able to parse a JSON listing into Objective-C and be able to call key/pairs into various different parts of an app. I'm pretty new to this so any advice would be great. i am trying to get values from the json array that get direct messages from twitter but i am getting the message error "Parse error: syntax error, unexpected T_AS, expecting '(' " in relation to the line "foreach (array as $direct_message) {" Also should i convert the array into a linear php array? Code: [Select] // create new instance $OAuth = new TwitterOAuth($consumer_key,$consumer_secret, $oAuthToken, $oAuthSecret); $direct_message = $OAuth->get('https://api.twitter.com/1/direct_messages.json?count=1&page='); function write_into_database ($direct_message) { $conn = mysql_connect("127.0.0.1", "Diego", "frafra") or die(mysql_error()); mysql_select_db('bot', $conn) or die(mysql_error()); foreach(array as $direct_message) { mysql_query("INSERT INTO 'followers' ('user_id', 'user_alias'), VALUES ('{$direct_message->sender_id}', '{$direct_message->sender_screen_name}, INSERT INTO 'd_messages'('message_id', 'message'), VALUES ('{$direct_message->id}' ,'{$direct_message->text})"); } write_into_database($direct_message); I have a simple ajax that passes data to a php script using jquery serialize. This is working good but where I am getting stuck is trying to pass json array into mysql. The json is outputting the correct data, but when I insert into db, it just says Array in the field. How can I convert(if that is the right term) json array to use in mysql. In the code I have posted, $box is an array from jquery which I normally use foreach to loop through array. What I need to do is convert $box after is has been encoded. Thanks Code: [Select] $box = $_POST['BRVbrtrv_boxnumber']; $list = array("activity" => $activity, "mobile" => $mobile, "company" => $company, "authorised" => $authorised, "service" => $service, "department" => $department, "address" => $address, "boxcount" => $boxcount, "box" => $box); $c = json_encode($list); echo $c; i want to edit a product and allocate industries to a product refer following link to view http://meriwebsite.net/envytech/admin/industryallocate.php?pageNum=1SELECT%20a.products_id,%20a.products_image,%20b.language_id,%20b.products_description,%20b.products_name%20%20%20FROM%20products%20a%20,%20products_description%20b%20WHERE%20a.products_id%20=%20b.products_id%20and%20language_id=1%20and%201%20order%20by%20%20b.products_id,%20%20b.products_description I can update prouct name and serial number but cannot get values for industries the do while loop for industry display is given below (displaying industry id before check box here) $iquery="SELECT * from industry "; mysql_select_db($database_DBconnect, $DBconnect); $iResult = mysql_query($iquery, $DBconnect) or die(mysql_error()); $irows = mysql_fetch_assoc($iResult); $itotalrows=mysql_num_rows($iResult); $j=-1; do { $j++; ?> <br /><?php echo "id=". $irows['id'];?><input name="ind[$i][$j]" type="checkbox" class="vardana12" id="ind[$i][$j]" value="<?php echo $irows['id'];?>" /> <?php echo $irows['name'];?> <?php } while ( $irows = mysql_fetch_assoc($iResult) ); ?> I am trying to display values using following code if ( (isset($_POST['sub'] )) or (isset($srno['sub'] ))) { echo "<br> count=".count($_POST['srno']); for($i=0; $i< count($_POST['srno']); $i++){ echo "on 'save' clicked <br>"; echo "<br> products ".$_POST['products_id'][$i]; echo "<br>srno ". $_POST['srno'][$i]; echo "<br>industry ".print_r($_POST['ind'][$i]); echo "<br>product name ". $_POST['products_name'][$i]; Updateindustry($_POST['products_id'][$i], $_POST['srno'][$i],$_POST['industry'][$i],$_POST['products_name'][$i]); } $update=1; $alert= "udation done"; } I am not getting correct values for $_POST['industry'][$i] please help I am having a hell of a time getting this to work. I need the keys in an array to be specific, not a sequential number or a row in my database. I need to add to the array through each loop of my while() statement. This code does it, but does not use the keys I specify, after the first entry, it starts assigning numbers to keys. Any guidance would be great. <?php require_once ('includes/config.php'); require_once ('includes/connect.php'); $echoarray = array(); $resultsql = mysql_query("SELECT * FROM clients")or die(mysql_error()); while($row = mysql_fetch_array($resultsql)){ if(empty($echoarray)){ $echoarray = array( 'id' => $row['ID'], 'name' => $row['First_Name'] . " " . $row['Last_Name'], 'price' => $row['Status'], 'number' => $row['Sex'], 'address' => $row['Phys_Street'], 'company' => $row['Agency'], 'desc' => $row['Notes'], 'age' => $row['Date_Birth'], 'title' => $row['Occupation'], 'phone' => $row['Phone'], 'email' => $row['Email'], 'zip' => $row['Phys_Zip'], 'country' => $row['Phys_City'] ); } else { array_push($echoarray, $echoarray['id'] = $row['ID'], $echoarray['name'] = $row['First_Name'] . " " . $row['Last_Name'], $echoarray['price'] = $row['Status'], $echoarray['number'] = $row['Sex'], $echoarray['address'] = $row['Phys_Street'], $echoarray['company'] = $row['Agency'], $echoarray['desc'] = $row['Notes'], $echoarray['age'] = $row['Date_Birth'], $echoarray['title'] = $row['Occupation'], $echoarray['phone'] = $row['Phone'], $echoarray['email'] = $row['Email'], $echoarray['zip'] = $row['Phys_Zip'], $echoarray['country'] = $row['Phys_City'] ); } Any Ideas? Code: [Select] $i=1; $selected=0; $uservalue=20; $numCols = 3; $numPerCol = ceil(20 / $numCols); echo "<table class=tuble><tr>"; for($col = 1; $col <= $numCols; $col++) { echo "<td>"; for($row = 0; $row < $numPerCol; $row++) { $resultRow = 20; if ($i<=$uservalue) { if ($i == $selected) { $checked = 'checked'; }else{ $checked = ''; } $styles = array( 'Blue Essense' => array('#2B8EFF', '#63CBFF', '50 Forum Gold'), 'veggie' => array('carrot', 'collard', 'pea') ); echo '<input type="radio" value="'.$i.'" name="form[color]">Blue Essence <b><a style="color:#2B8EFF;text-shadow:#63CBFF 2px 1px 1px" href="u.php?id='.$pun_user['id'].'">'.$pun_user['username'].'</a></b><br>'; } else { echo '<label for="s'.$i.'"><input type="radio" value="'.$i.'" name="form[star]" disabled><b><a href="u.php?id='.$pun_user['id'].'">'.$pun_user['username'].'</a></b><br>'; } $i++; } echo "</td>"; } echo "</tr></table>"; Okay, see the $styles array? Code: [Select] $styles = array( 'Blue Essense' => array('#2B8EFF', '#63CBFF', '50 Forum Gold'), 'veggie' => array('carrot', 'collard', 'pea') ); The first is hex code, background, and 2nd is #63CBFF (Front color) and the 3rd is how much it costs I need those arrays to echo out correspondent with my Code: [Select] echo '<input type="radio" value="'.$i.'" name="form[color]">Blue Essense<b><a style="color:#2B8EFF;text-shadow:#63CBFF 2px 1px 1px" href="u.php?id='.$pun_user['id'].'">'.$pun_user['username'].'</a></b> (50 Forum Gold)<br>'; See how the style="color etc/etc" I need to grab the data from $styles to go into the correct spots, Is this feasable? Long story short, I need to explode those arrays out somehow, any idea? What am I missing here? The array: protected $form_bonus = array( "Attacker" => array( "Ashwin" => array( "normal" => 1.15, "rps" => 1.38), "Cordelon" => array( "normal" => 1.15, "rps" => 1.38), "Mersan" => array( "normal" => 1.15, "rps" => 1.38), "Phlanixian" => array( "normal" => 1.195, "rps" => 1.494), "Slythe" => array( "normal" => 1.15, "rps" => 1.38) ), "Defender" => array( "Ashwin" => array( "normal" => 1.15, "rps" => 1.38), "Cordelon" => array( "normal" => 1.15, "rps" => 1.38), "Mersan" => array( "normal" => 1.15, "rps" => 1.38), "Phlanixian" => array( "normal" => 1.15, "rps" => 1.38), "Slythe" => array( "normal" => 1.15, "rps" => 1.38) ) ); accessing it: $bonus *= form_bonus[$this->role][$this->race]['rps']; error: PHP Parse error: syntax error, unexpected '[' Whats the most efficient way of searching within a multi dimensional array? My Array = Array ( => Array ( => Item 1 [title] => Item 1 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) [1] => Array ( => Item 2 [title] => Item 2 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) ) String to find = '21' If (MY ARRAY contains STRING TO FIND) {} Clearly in this case there are several '21' (s) so if I only wanted to search the [eventDay] keys...would there be a fast effective and efficient manner? Thoughts and help gratefully received. Will Hi people I need a way to loop through an array where $imgid is some random number assigned to each array element and there are 4 fields id, url, tnurl, caption per array element. I need to extract these 4 fields in the same loop iteration. Thanks Code: [Select] $_SESSION['imagegallery'][$imgid]['id']; $_SESSION['imagegallery'][$imgid]['url']; $_SESSION['imagegallery'][$imgid]['tnurl']; $_SESSION['imagegallery'][$imgid]['caption']; example: Code: [Select] $_SESSION['imagegallery'][347]['id']; $_SESSION['imagegallery'][347]['url']; $_SESSION['imagegallery'][347]['tnurl']; $_SESSION['imagegallery'][347]['caption']; $_SESSION['imagegallery'][892]['id']; $_SESSION['imagegallery'][892]['url']; $_SESSION['imagegallery'][892]['tnurl']; $_SESSION['imagegallery'][892]['caption']; |