473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

array

i've got numbers written in file like that:

0.005465
0.004564
....

I want to read them into an array and have the same effect like:
$arr=array(0.005465,0.004564,..)

Do you know how to o it?

i tried something like that:

$file_name = "file_name";
$fp=fopen($file_name,"r");
$arr=implode(' ',file($file_name));
$arr2=explode(' ',$arr);

and wanted that an arr2 to be my array..

but it has no result...
Jul 17 '05 #1
3 1887
On Fri, 16 Jul 2004 12:33:31 -0500, Piotr Wolski wrote:
i've got numbers written in file like that:

0.005465
0.004564
...

I want to read them into an array and have the same effect like:
$arr=array(0.005465,0.004564,..)

Do you know how to o it?

i tried something like that:

$file_name = "file_name";
$fp=fopen($file_name,"r");
$arr=implode(' ',file($file_name));
$arr2=explode(' ',$arr);

and wanted that an arr2 to be my array..

but it has no result...

You're using 2 methods here to do "the same thing". I'd suggest reading
about the file() function on php.net =)
$arr = file($file_name);
That's it! $arr is now your array as you're requiring. To test this, try:
<?php
$arr = file($file_name);
var_dump($arr);
?>
HTH =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2

"Ian.H" <ia*@WINDOZEdigiserv.net> wrote in message
news:pa****************************@bubbleboy.digi serv.net...
You're using 2 methods here to do "the same thing". I'd suggest reading
about the file() function on php.net =)
$arr = file($file_name);
That's it! $arr is now your array as you're requiring. To test this, try:
<?php
$arr = file($file_name);
var_dump($arr);
?>


Since file() returns elements with newline character attached, you might
want to do this:

$arr = array_map('floatval', $file_name);
Jul 17 '05 #3
Chung Leong wrote:
"Ian.H" <ia*@WINDOZEdigiserv.net> wrote in message
news:pa****************************@bubbleboy.digi serv.net...
You're using 2 methods here to do "the same thing". I'd suggest reading
about the file() function on php.net =)
$arr = file($file_name);
That's it! $arr is now your array as you're requiring. To test this, try:
<?php
$arr = file($file_name);
var_dump($arr);
?>

Since file() returns elements with newline character attached, you might
want to do this:

$arr = array_map('floatval', $file_name);


thanks, it finally worked, however you made mistake, it should be:

$arr=array_map('floatval',$arr);

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.