PHP - Array Variable Index In That Rare Simplexml Functions
hi very good, hi very good, I have a label on a form select and I get that value with $ _POST like this: $ _POST like this:
$ gallery = array ($ _POST ['gallery']); and that value will put it he $ image = $ sitemap-> gallery [$ gallery] -> addChild ('image'); the problem is giving me error is as follows: Fatal error: Call to a member function addChild () on a non-object in I do not understand is that if I put a value directly asin me do it like so: $ gallery = 0; $ Image = $ sitemap-> gallery [$ gallery] -> addChild ('image'); I do well, what happens is that I want the user to choose, Kind of strange as it may fix. Similar TutorialsHi All,
I'm new to PHP (not to coding) - and I've been able to bang out most answers using books, the web and brue force - but this one has me stumped.
(If it's been covered before, sorry, I'm being lazy for not searching)...
So, here's the problem:
I have a call to my internal system that returns XML data via a SOAP call.
The call works great - data is returned as I would expect.
Like I've read, I put said data into a variable usng simpleXML like this: $xml = simplexml_load_string($response3); ($response3 being where the raw data is)
When I do a var_dump of $xml, I get this:
SimpleXMLElement Object ( [ICProductAvailByWhseResult] => SimpleXMLElement Object ( [errorMessage] => SimpleXMLElement Object ( ) [arrayAvailability] => SimpleXMLElement Object ( [ICProductAvailByWhse.output.Availability] => Array ( [0] => SimpleXMLElement Object ( [productCode] => xxx [description1] => yyy [description2] => zzz [warehouse] => aaa [netAvailable] => bbb ) [1] => SimpleXMLElement Object ( [productCode] => xxx [description1] => yyy [description2] => zzz [warehouse] => aaa [netAvailable] => bbb ) [2] => SimpleXMLElement Object ( [productCode] => xxx [description1] => yyy [description2] => zzz [warehouse] => aaa [netAvailable] => bbb ) **** Edited, I got real data, not xxx,yyy, etc... **** Now the issue: It seems like I have everything in place - all I need now is to get my data off to variables for display. I've tried everything I can think of and I just can't seem to get it. I ran $xml->getName() and it gave me: ICProductAvailByWhseResult So, simple I think, I should be able to print something like $xml->ICProductAvailByWhseResult[0]->warehouse and I should get something, right? Nope. So I try $xml->ICProductAvailByWhseResult[1]->warehouse and I get a notice that I'm trying to get to a property of a non-object. What am I missing? I come from a VB backgound, so I understand array's and such - but this one has be stumped. And help would be greatly appreciated... Thanks!! Greetings, I'm building a very basic form and one of the checks I want to preform is far more difficult for me than I would have imagined. I am not very proficient (at all) with php, any help would be extremely appreciated. All I am trying to do is add a test/check with an error that the end user would see if they are trying to 'check out' a unit number that has already been checked out and has not been flagged as not 'returned'. Here is the snippet in question: Code: [Select] $checkunitid = $_POST['uniid']; //checkexists($checkunitid); $q="select unit_id from check_in_out where `returned` = 'N' and unit_id = '" . $uniid . "'" function checkexists() { $result = mysql_query($q) or die(mysql_error()); if($row = mysql_fetch_array($result)) { return 1; } return 0; } if (checkexists()) { echo "<font size=7 color=red>record exists</font>"; exit(); } i have two functions. In function two it has $id=9. how do i get function one to echo $id? how do i adjust the below example to accomplish this? Code: [Select] $newdb = new Database(); class Database { function one() { $newdb->two(); echo $id; } function two() { $id = 9 return $id; } } This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=314334.0 I have been working on a PHP site on an actual server that is online. This is bad practice, and a huge pain in the ass as I need to upload all files to test whether the work. So I've installed XAMPP and have transferred my database and website to the root folder. Now I get these errors: Notice: Undefined index: username in C:\xampp\htdocs\members.html on line 19 This error is produced he Code: [Select] session_start(); $fc_user = ''; $fc_pass = ''; if (isset($_SESSION['fc_handle']) && isset($_SESSION['fc_password'])) { $fc_user = $_SESSION['fc_handle']; $fc_pass = base64_encode($_SESSION['fc_password']); } else if (isset($_POST['username']) && isset($_POST['password'])) { $fc_user = $_POST['username']; $fc_pass = base64_encode($_POST['password']); } else if ((($_POST['username'] == '') || ($_POST['password'] == '')) && (($_SESSION['fc_handle'] == '') || ($_SESSION['fc_id'] == ''))) /// <-- THIS IS LINE 19 { header("Location: http://www.familychores.com/index_coming.html"); exit; } I can't figure this out ... Sorry again , but it seems I still have some problem with my $_GET. Here is the error I get: Notice: Undefined variable: id in /opt/lampp/htdocs/EMC/customer-search.php on line 248 Notice: Undefined index: Page in /opt/lampp/htdocs/EMC/customer-search.php on line 255 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/EMC/customer-search.php on line 302 And my code for second error: Code: [Select] $Per_Page = 2; // Per Page $Page = isset($_GET["Page"]); if (!$_GET["Page"]) { $Page=1; } I'm not really sure what's the problem with my first and third error so I will post the whole code he Code: [Select] <?php require_once("./include/fg_membersite.php"); require_once("./include/membersite_config.php"); $objConnect = mysql_connect("localhost","root","") or die(mysql_error()); $objDB = mysql_select_db("EMC"); $haha = $fgmembersite->UserEmail(); $_SESSION['storedemail']= $haha; $query4 = mysql_query("SELECT * FROM Register WHERE Email= '$haha'"); while ($row4 = mysql_fetch_array($query4)){ $id = $row4['ID']; } mysql_free_result($query4); ?> <html> <body> <form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>"> <table width="599" border="1"> <tr> <th>Keyword <input name="txtFirstName" type="text" id="txtFirstName" value="<?= isset($_GET["txtFirstName"]) ;?>"> <input name="txtLastName" type="text" id="txtLastName" value="<?= isset($_GET["txtLastName"]) ;?>"> <input name="txtCell" type="text" id="txtCell" value="<?= isset($_GET["txtCell"]) ;?>"> <? $opselect="SELECT DISTINCT Custgroup FROM UserAddedRecord"; $result = mysql_query ($opselect); while($nt=mysql_fetch_array($result)) { ?> <option><?= $nt[Custgroup]?></option>"; <? } ?> </select> <input type="submit" value="Search"> </tr> </table> </form> <? if (isset($_GET["txtFirstName"]) != "" || isset($_GET["txtLastName"]) != "" || isset($_GET["txtCell"]) != "" || isset($_GET["txtGroup"]) != "") { $objConnect = mysql_connect("localhost","root","") or die(mysql_error()); $objDB = mysql_select_db("EMC"); // Search By Name or Email $strSQL = "SELECT * FROM UserAddedRecord WHERE (FirstName LIKE '%".$_GET["txtFirstName"]."%' and LastName LIKE '%".$_GET["txtLastName"]."%' and Cell LIKE '%".$_GET["txtCell"]."%' and Custgroup LIKE '%".$_GET["txtGroup"]."%')"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $Num_Rows = mysql_num_rows($objQuery); $Per_Page = 2; // Per Page $Page = isset($_GET["Page"]); if (!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $strSQL .=" order by addedrec_ID DESC LIMIT $Page_Start , $Per_Page"; $objQuery = mysql_query($strSQL); ?> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">CustomerID </div></th> <th width="98"> <div align="center">Name </div></th> <th width="198"> <div align="center">Email </div></th> <th width="97"> <div align="center">CountryCode </div></th> <th width="59"> <div align="center">Budget </div></th> <th width="71"> <div align="center">Used </div></th> </tr> <? while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><div align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?=$objResult["addedrec_ID"];?>"></div></td> <td><div align="center"><?=$objResult["addedrec_ID"];?></div></td> <td><?=$objResult["FirstName"];?></td> <td><?=$objResult["LastName"];?></td> <td><div align="center"><?=$objResult["MobileCompany"];?></div></td> <td align="right"><?=$objResult["Cell"];?></td> <td align="right"><?=$objResult["Workphone"];?></td> </tr> <? } ?> </table> <br> Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page : <? if($Prev_Page) { if($_GET["txtFirstName"] == "") { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> "; } else { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> "; } } for($i=1; $i<=$Num_Pages; $i++){ if($i != $Page) { echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]"; } else { echo "<b> $i </b>"; } } if($Page!=$Num_Pages) { if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "" && $_GET["txtCell"] == "") { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtGroup=$_GET[txtGroup]'>Next>></a> "; } else if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "") { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> "; } else if($_GET["txtFirstName"] == "" ) { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> "; } else { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> "; } } mysql_close($objConnect); } else { $strSQL = "SELECT * FROM UserAddedRecord WHERE user_id='$id'"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $Num_Rows = mysql_num_rows($objQuery); $Per_Page = 2; // Per Page $Page = isset($_GET["Page"]); if (!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $strSQL .=" order by id DESC LIMIT $Page_Start , $Per_Page"; $objQuery = mysql_query($strSQL); ?> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="198"> <div align="center">First Name </div></th> <th width="198"> <div align="center">Last Name </div></th> <th width="250"> <div align="center">Mobile Company </div></th> <th width="100"> <div align="center">Cell </div></th> <th width="100"> <div align="center">Workphone </div></th> <th width="100"> <div align="center">Group </div></th> </tr> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>"; echo "<td>$objResult[addedrec_ID] </td>"; echo "<td>$objResult[FirstName]</td>"; echo "<td>$objResult[LastName] </td>"; echo "<td>$objResult[MobileCompany] </td>"; echo "<td>$objResult[Cell] </td>"; echo "<td>$objResult[WorkPhone] </td>"; echo "<td>$objResult[Custgroup] </td>"; echo "</tr>"; } echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">"; if(isset($_POST['delete'])) // from button name="delete" { $checkbox = $_POST['checkbox']; //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($d=0;$d<$countCheck;$d++) { $del_id = $checkbox[$d]; $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id"; $result2=mysql_query($sql); } if($result2) { header('Location: customer-adddata.php'); } else { echo "Error: ".mysql_error(); } } echo "</form>"; ?> </table> <br> Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page : <? if($Prev_Page) { if($_GET["txtFirstName"] == "") { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> "; } else { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> "; } } for($i=1; $i<=$Num_Pages; $i++){ if($i != $Page) { echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]"; } else { echo "<b> $i </b>"; } } if($Page!=$Num_Pages) { if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "") { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> "; } else if($_GET["txtFirstName"] == "" ) { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> "; } else { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> "; } } mysql_close($objConnect); } ?> </body> </html> And one more error , when I tried to search data and typed some keywords in the textbox , three of the textbox will keep return me value "1" , I really tried to solve the error but still there....can anyone help me for this? Thanks in advanced. I have a php page that is trying to pass a variable like this: echo "<tr><td bgcolor='white'>" . $company_id . "</td><td bgcolor='white'><a href='companyusers.php?name=" . $company_name . "'>" . $company_name . "</a></td><td bgcolor='white'>" . $company_email . "</td><td bgcolor='white'>" . $company_status . "</td></tr>"; Then when some one clicks on that link they variable with it's value should go with the url and I'm trying to assign a variable like this: $company_name = $_POST['name']; It is not working!!! I get that "Notice: Undefined index: name in 'directory of page' on line 100" Can someone help please? I attempted to try to do what was in the comments, but I am not able to do it any help is appreciated Code: [Select] <?php $a = array(9, 3, 1, 0, 99, 2, 5, 6, 32, 1, 55); $b = array(9, 18, 1, 0, 23, 22, 4, 6, 5, 32, 55); function getAverage () { echo "The average is " . array_sum($a) . "\n"; // Show the sum of the entire array (should display 19.36) } getAverage(); echo "<br><br>"; function highestValue() { echo $a[max]; // Show the index value of the highest number (should display 4) echo $a(max); // Show the value of index 4 (should display 99) echo $a[min]; // Show the index value of lowest number (should display 3) echo $a(min); // Show the value of index 4 (should display 0) } highestValue(); echo "<br><br>"; function displayMatch() { //Write a function that tests the values of both arrays. If the values at the same index match display the following: "The values at <insert the matching index> match." } displayMatch(); ?> I tried searching for this but I didn't find anything. I have some php code that when loaded from a web page draws some numbers from a database and outputs. Should be no problem I thought The code involves a mysql query. This is an edited sample: $query = "SELECT `count` FROM `uc` WHERE `id` = 17"; $result = mysql_query($query, $dbh) or die(mysql_error()); $row = mysql_fetch_array($result, $dbh); Now after this I normally access $row as $row[0] and this works great most of the time. However about 10% of the time it returns an error: "Notice: Undefined offset: 0" My investigation using print_r($row); shows that sometimes it returns Array ( => 619 ) and sometimes it returns Array ( [count] => 619 ) Why the inconsistency? How can I make it always use a numeric index? 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]; } Hi, As the title suggests I am unsure on how to first run a query which stores values into an array. I then need to run a function multiple times but use the array within the function. How is this possible? I have had no luck figuring it out yet. 1. RUN QUERY 2. BUILD ARRAY USING QUERY RESULTS 3. RUN FUNCTION MULTIPLE TIMES 4. WITHIN FUNCTION I NEED TO USE ARRAY Many thanks Simon I've got a multidimensional array that has 2 columns. The first column is numerical (country_id), and the second column is text (country_name), which may or may not be data that will be turned into an array. Looks something like this: column 1 (index 0) = 42 column 2 (index 1) = Great Britain|England I use a while loop to create an array of these rows, then a use a foreach loop to go through index[1] of each row. If there is a single name for a country, it is added to a new array, but if there is more than one name for a country, then both names are added to the new array. So, for example, if we had this data: row1 column 1 (index 0) = 12 column 2 (index 1) = Algeria row2 column 1 (index 0) = 22 column 2 (index 1) = Ethiopia row3 column 1 (index 0) =42 column 2 (index 1) = Great Britain|England Then the final array would look like this: index[0] = 12 index[1] = Algeria index[0] = 22 index[1] = Ethiopia index[0] = 42 index[1] = Great Britain index[0] = 42 index[1] = England Now I would like to sort by index[1] to get the following alphabetical order: index[0] = 12 index[1] = Algeria index[0] = 42 index[1] = England index[0] = 22 index[1] = Ethiopia index[0] = 42 index[1] = Great Britain What do I use? I've fooled around with sort, usort, asort ... can't figure it out. Thanks in advance. Hi, I am a little bit new to php, and I am learning about array functions. I just wanted to know the difference between implode and explode in arrays, and how each of them would be used? Thank you! 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- I did this and it works... based on the date, the values in the array (from 1 to 9) are echoed by calling $num. Code: [Select] <?php $start = "2012-02-27"; $now = date("Y-m-d"); $week2 = strtotime(date("Y-m-d", strtotime($start)) . " +1 week"); $week2_st = date("Y-m-d", $week2); $week3 = strtotime(date("Y-m-d", strtotime($start)) . " +2 weeks"); $week3_st = date("Y-m-d", $week3); $week4 = strtotime(date("Y-m-d", strtotime($start)) . " +3 weeks"); $week4_st = date("Y-m-d", $week4); $week5 = strtotime(date("Y-m-d", strtotime($start)) . " +4 weeks"); $week5_st = date("Y-m-d", $week5); $week6 = strtotime(date("Y-m-d", strtotime($start)) . " +5 weeks"); $week6_st = date("Y-m-d", $week6); $week7 = strtotime(date("Y-m-d", strtotime($start)) . " +6 weeks"); $week7_st = date("Y-m-d", $week7); $week8 = strtotime(date("Y-m-d", strtotime($start)) . " +7 weeks"); $week8_st = date("Y-m-d", $week8); $week9 = strtotime(date("Y-m-d", strtotime($start)) . " +8 weeks"); $week9_st = date("Y-m-d", $week9); $var_name = array('1', '2','3','4,'5','6','7,'8','9'); if ($now <= $week2_st){ $num = $var_name[0];} elseif($now >= $week2_st && $now <= $week3_st){ $num = $var_name[1];} elseif($now >= $week3_st && $now <= $week4_st){ $num = $var_name[2];} elseif($now >= $week4_st && $now <= $week5_st){ $num = $var_name[3];} elseif($now >= $week5_st && $now <= $week6_st){ $num = $var_name[4];} elseif($now >= $week6_st && $now <= $week7_st){ $num = $var_name[5];} elseif($now >= $week7_st && $now <= $week8_st){ $num = $var_name[6];} elseif($now >= $week8_st && $now <= $week9_st){ $num = $var_name[7];} elseif($now >= $week9_st){ $num = $var_name[8];} else{ $num :'( = $var_name[0];} ?> I'm trying to do a for loop so the index # increments by one and i only call $r instead $var_name[0], $var_name[1], $var_name[2], and so one. Any ideas? Code: [Select] $count = count($var_name); for ($i = 0; $i < $count; $i++) { $r = $var_name[$i]; } I am wondering whether there is a way to do a foreach loop for an array, without starting at index[0]. Say, for example, I wanted to start displaying the contents of a 20 item array starting at index 5, what is the best way to do it? I know of this way, but it seems too crude (ie. there has to be a better way): $count = 0; foreach($array as $item) { if ($count > 5) {echo $item;} $count++; } Any other ideas?? I have been researching php.net regain the function parse_ini_file() I know you can pass it an actual ini file but what if you already saved the ini file as a string and saved the string in a variable can you pass that variable to the function? I am getting the following error Code: [Select] [function.parse-ini-file]: failed to open stream: No such file or directory in this is how I am calling it. Code: [Select] $settings = parse_ini_file($data); echo $settings["mac"]; I'm using the code below to on echo certain words based on their index/key value, this works fine however, im trying to only do this in exploded quotes... the problem is, exploding quotes turns the portion into an array which cant be passed to str_word_count... how can i do the same thing only inside quotes. So that hello world "this is a test" would become: Code: [Select] Hello World This [0] => Is [1] => a [2] => Test [3] Im trying to always remove say the 4th word in quotations, or maybe the 3rd and 4th, whatever i want to omit i leave out from the echo, so echo $data[0].' '.$data[3].'; would output "This Test" omitting "Is A" Code: [Select] $data = 'hello world "this is a test"'; $data = str_word_count($data, 1); echo $data[1].' '.$data[2].' '.$data[0]; I am just trying to use Associate array in another php file through session.
file1.php <?php $age = array(); $_SESSION["age"] = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); foreach($_SESSION["age"] as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>\n"; } ?> OUTPUT: Key=Peter, Value=35 Key=Ben, Value=37 Key=Joe, Value=43 file2.php <?php session_start(); foreach( $_SESSION["age"] as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>\n"; } ?> OUTPUT: PHP Notice: Undefined index: age in session.php on line 3 PHP Warning: Invalid argument supplied for foreach() in session.php on line 3 Why am I getting this error? Above is just example I tried to demonstrate for asking question for other issue, unfortunately I got new error in this example. But actual issue was, I was trying to plot graph using library which requires only Associate array, where the data is formed in file1.php. But I get only last index value displayed in file2.php even in graph or in echo. I don't understand why other values are not displayed in file2.php Please point me what is going wrong, Thanks. Good morning! I have a two dimensional array, basically a table (see code below). I want to get a value from the array using two methods: 1) Using the row's key: $NewValue = $MyArray[$UniqueKey]; 2) Using the row's index (row number, so to speak): $NewValue = $MyArray[$RowNumber]; The second print statement in the code below does not work. Both print statements should output the same value. Is there an easy way to do this? The table has hundreds of rows and I will not know the key value of row 879 nor can I generate it. So I cannot use array_keys(). And I DO NOT want to start at the first row and count up to the 879th row. Any clever ideas to share and enlighten? Thanks! <?php // Initialize the array keys and values $MyArray = array(); $MyArray['first']['col1'] = 'abc'; $MyArray['first']['col2'] = 'def'; $MyArray['first']['col3'] = 'ghi'; $MyArray['second']['col1'] = 'jkl'; $MyArray['second']['col2'] = 'mno'; $MyArray['second']['col3'] = 'pqr'; $MyArray['third']['col1'] = 'stu'; $MyArray['third']['col2'] = 'vwx'; $MyArray['third']['col3'] = 'yz'; $MyArray['fourth']['col1'] = 'a1a'; $MyArray['fourth']['col2'] = 'b2b'; $MyArray['fourth']['col3'] = 'c3c'; $MyArray['fifth']['col1'] = 'ddd'; $MyArray['fifth']['col2'] = 'eee'; $MyArray['fifth']['col3'] = 'fff'; // Two methods to get a value. Second one does nothing. print"{$MyArray['third']['col2']}</br>"; print"{$MyArray[2]['col2']}</br>"; ?> |