tarun Posted March 10, 2007 Share Posted March 10, 2007 My Website Has A PM (PrivateMessaging) System It Will Use Arrays And The PMs Are Stored In: msgs/$user.php And Access Using: include("msgs/$user.php"); <?php $msg = array( 'MsgTitle1'=>array( 'From1', 'MsgBody1', 'TimeReceived1' ), 'MsgTitle2'=>array( 'From2', MsgBody2', 'TimeReceived2' ), 'MsgTitle3'=>array( 'From3', 'MsgBody3', 'TimeReceived3' ) ); ?> What What The send.php, inbox.php, delete.php Page Look Like In Other Words How Do I View All The Array Contents (foreach?) And Delete And Add To The Array Thnx, Tarun Link to comment https://forums.phpfreaks.com/topic/42149-solved-multidimensionalarrays-pm-system/ Share on other sites More sharing options...
tarun Posted March 11, 2007 Author Share Posted March 11, 2007 BuMp Link to comment https://forums.phpfreaks.com/topic/42149-solved-multidimensionalarrays-pm-system/#findComment-204830 Share on other sites More sharing options...
Barand Posted March 11, 2007 Share Posted March 11, 2007 <?php $msg = array( 'MsgTitle1'=>array( 'From1', 'MsgBody1', 'TimeReceived1' ), 'MsgTitle2'=>array( 'From2', 'MsgBody2', 'TimeReceived2' ), 'MsgTitle3'=>array( 'From3', 'MsgBody3', 'TimeReceived3' ) ); /** * to list the array */ foreach ($msg as $title => $mdata) { echo "<br><b>Message title : $title</b><br>"; foreach ($mdata as $item) { echo "$item<br>"; } } /** * add new item */ $msg['MsgTitle4'] = array ('From4', 'MsgBody4', 'TimeReceived4'); /** * delete msg2 */ unset ($msg['MsgTitle2']); ?> Link to comment https://forums.phpfreaks.com/topic/42149-solved-multidimensionalarrays-pm-system/#findComment-204840 Share on other sites More sharing options...
Glyde Posted March 11, 2007 Share Posted March 11, 2007 Don't use the message titles as the offsets, use integers, such as: <?php $messageList = array( array('title' => 'Message title', 'sender' => 'sender', 'body' => 'Body'), array('title' => 'Message title', 'sender' => 'sender', 'body' => 'Body')); ?> If you use titles as offsets and two people send a message with the same title, the older one will be removed from the array. Link to comment https://forums.phpfreaks.com/topic/42149-solved-multidimensionalarrays-pm-system/#findComment-204843 Share on other sites More sharing options...
Barand Posted March 11, 2007 Share Posted March 11, 2007 There won't be two in there with the same title as the second would have overwritten the first when added Link to comment https://forums.phpfreaks.com/topic/42149-solved-multidimensionalarrays-pm-system/#findComment-204844 Share on other sites More sharing options...
tarun Posted March 11, 2007 Author Share Posted March 11, 2007 Thnx Every1 I Really Appreciate It Link to comment https://forums.phpfreaks.com/topic/42149-solved-multidimensionalarrays-pm-system/#findComment-204848 Share on other sites More sharing options...
Glyde Posted March 11, 2007 Share Posted March 11, 2007 There won't be two in there with the same title as the second would have overwritten the first when added If he's simply using fwrite(), then no. It would just append the data to the end of the file. But you still just proved my point. The second message would replace the first, whether it overwrites it from the file, or just doesn't display when printed...either way the first one is gone. Link to comment https://forums.phpfreaks.com/topic/42149-solved-multidimensionalarrays-pm-system/#findComment-204992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.