note 93776 added to language.types.array

From: Date: Mon, 28 Sep 2009 18:04:00 +0000
Subject: note 93776 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-161128@lists.php.net to get a copy of this message
You can actually create arrays in arrays; just consider the following code: <?php function LoadData($file) { $lines = file($file) or die('Could not open file'); foreach($lines as $line) { $i[] = array($line); print_r($i[1]) } LoadData('file.csv'); ?> A (.csv-)file is loaded into the function LoadData and stored in the array $lines. Then foreach puts the values from the $lines-array into $line and $i is defined as an array of the array $line. Please note that this type of code could take up much of CPU-usage; it generates a multi-dimensional array. When $i is printed (in the example, value 1 of the array) it would display: Array ( [0] => Array ( [0] => 7;75;X;0;0;1;0;3;Gr;Br;Do;0;0;0;0;0;0;0;0; [1] => ;200;K;0;0;0;0;0;Gr;0;0;0;0;ZL;0;0;0;0;0; [2] => ;260;Z;;;;;;Gr;;;;;VL;;;;;; [3] => ;270;K;;;;1;;Gr;Br;Li;;;;;;;;; [4] => ;500;V;;;;;;Br;;;;;;;;;;; [5] => 6;60;X;;;;;;;;;;;;;;;;; [6] => ;80;K;;;;;;Gr;;;;;ZL;;;;;; [7] => ;210;Z;;;;;;Gr;;;;;;;;;;; ) ---- Server IP: 91.199.167.18 Probable Submitter: 82.72.13.129 ---- Manual Page -- http://www.php.net/manual/en/language.types.array.php Edit -- https://master.php.net/note/edit/93776 Del: integrated -- https://master.php.net/note/delete/93776/integrated Del: useless -- https://master.php.net/note/delete/93776/useless Del: bad code -- https://master.php.net/note/delete/93776/bad+code Del: spam -- https://master.php.net/note/delete/93776/spam Del: non-english -- https://master.php.net/note/delete/93776/non-english Del: in docs -- https://master.php.net/note/delete/93776/in+docs Del: other reasons-- https://master.php.net/note/delete/93776 Reject -- https://master.php.net/note/reject/93776 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161128) next »