tarun Posted March 26, 2007 Share Posted March 26, 2007 My Array Which Is Stored In items.php Is Accesed By Pages Using include 'items.php'; items.php Looks Like This: <?php $itemList = array( '000001'=>array('ID' => '000001','name' => 'Item 1','price' => '99.99','img' => 'images/1.jpg','cat' => 'Category 1'), '000002'=>array('ID' => '000002','name' => 'Item 2','price' => '49.99','img' => 'images/2.jpg','cat' => 'Category 2') ); ?> And This Code Is Used To Add To The Array: $itemList['000003'] = array('ID' => '000003','name' => 'Item 3','price' => '69.99','img' => 'images/3.jpg','cat' => 'Category 3'); But It Doesn't Change The Contents Of items.php Any Help... Thnx, Tarun Link to comment https://forums.phpfreaks.com/topic/44381-arrays/ Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 Why would it change the contents of items.php unless you were writing to that page. In order to change the contents (if I am reading this right) of items.php you have to open it for writing and write that line to it. Now if you did it like this : <?php $itemList['000003'] = array('ID' => '000003','name' => 'Item 3','price' => '69.99','img' => 'images/3.jpg','cat' => 'Category 3'); include('items.php'); ?> The above will be over written with this: $itemList = array( '000001'=>array('ID' => '000001','name' => 'Item 1','price' => '99.99','img' => 'images/1.jpg','cat' => 'Category 1'), '000002'=>array('ID' => '000002','name' => 'Item 2','price' => '49.99','img' => 'images/2.jpg','cat' => 'Category 2') ); To solve that problem do this: <?php $itemList = array(); $itemList['000003'] = array('ID' => '000003','name' => 'Item 3','price' => '69.99','img' => 'images/3.jpg','cat' => 'Category 3'); include('items.php'); ?> // items.php <?php $itemList['000001'] = array('ID' => '000001','name' => 'Item 1','price' => '99.99','img' => 'images/1.jpg','cat' => 'Category 1'); $itemList['000002'] = array('ID' => '000002','name' => 'Item 2','price' => '49.99','img' => 'images/2.jpg','cat' => 'Category 2'); ?> Or do the declaration after the items.php list is called for item 3. Link to comment https://forums.phpfreaks.com/topic/44381-arrays/#findComment-215524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.