Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Simple Array Out Of Multidim. Array


I've been puzzling for two days on this problem and all that's related to it and despite the wealth of similar examples I just can not manage to find a satisfactory solution to my problem. Code:




View Complete Forum Thread with Replies

Related Forum Messages:
Multidim Array Sort
I am wondering if someone can point me to the needed sort function. There are so many of
them that I simply got lost by reading their descriptions. I try to explain what I need.

I have a multidimensional array and I have a function that outputs it as a table.

$arr[0] contains an array that contains usernames
$arr[1] contains an array that contains real names
$arr[2] contains an array that contains e-mails
etc...
$arr[last] contains integers for users "levels"

My function outputs users with their datas in the columns. Each column means one user.

Now I want to sort this whole array by levels. So, all other data should be sorted
according to the pattern in levels row.

How is this thing done?

View Replies !
UNSET'ing Multidim Array Elements And Reseting Keys
I have a script that calls code plugins that return associative arrays:

$aData[0]...
$aData[1]...
$aData[2]...
$aData[3]...
$aData[4]...
$aData[5]...
$aData[6]...
$aData[7]...

I would like to run a search on the array data and UNSET the array rows that do not meet my criteria (this part I know how to do). This means I end up with:

$aData[0]...
$aData[1]...
$aData[3]...
$aData[5]...

Once this is done, I'd like to reset the first level key names to be consecutive like this (this is where I need help; I'm hoping for a existing builtin function but so far have not been able to find one):

$aData[0]...
$aData[1]...
$aData[2]...
$aData[3]...

I'll find out soon enough once this is working but does anyone know is UNSET eats up alot of time? on large arrays?

View Replies !
Simple Array
Running some queries and get an array returned that looks like this:

Array ( => Array ( [max] => 4 ) )
Just wondering how to access '4'. Been trying simple echo commands (echo $maxID; echo $maxID[0]; echo $maxID[1]; echo $maxID['max']; but cant get anything. Obviously its something stupid im not realizing, just need a shove in the right direction.

View Replies !
Simple Array From DB Result
I have a simple DB query which puts a set of values into a pull-down menu as follows:-

View Replies !
Simple Array Question
Hi there just wanted to ask something I currently have this snippet of code which is taken from log cleaner script I have running or working on getting working correctly.
What I want to know is, down the bottom where it returns $data, how would I then extract that content to include in an email message??

View Replies !
Simple Algorithim With Array
i have got to produce a algorithm for an array. Firstly the array has ten numbers in it then i have to find the avg of the ten then after that i have to find the next largest number after the avg e.g if avg = 3.4 then other numbers are 6,8,5,10 then the answer would be 5.

View Replies !
Simple Calculation Between Array
i have two arrays :

$quantity = array(1,2,3);
$price = array(15.45,12.3,23);

how do i make those two arrays for a multiply calculation like this :

$total = $quantity * $price;

i want the total of the calculations in a new array

View Replies !
How Much ~ Memory Does A Simple Array Eat?
say 500 items stored temporarily into an array variable with an id and title

$temp_array[$ID] = $title;
(title = varchar 150 character max)

it's for a page where it may,.. or may not be called... but when it is called, it could be called 1 or 10 times (it's a search page...) so I'm wondering if it's more sensible to load into memory temporarily for a split second rather than do up to 10 mysql queries for the title..

again, assume an array with 500 items~ is it no point worrying about the 4k or, what even less? maybe 1k?

View Replies !
SecureURL Simple Array
What I am looking to have done is for someone to setup and array for an existing script. For you guys I am sure this would be quite easy, I have tried several different approaches myself and failed miserably each time. So perhaps I am missing the simple answer here. Basically this script takes the URL strings and encrypts them for when it gets passed. Problem is it is only doing this for links that are internal to the document. I'd like it to do it for all the links.

View Replies !
Simple Delete From Array?
Any way to do a simple delete from array? In other words, what would be the *easiest* (and fastest php runtime) way to delete "banana" from the following array:

$my_array = array(
"apple",
"banana",
"grape",
"lime"
);

.....so that $my_array will now be:

$my_array = array(
"apple",
"grape",
"lime"
);

View Replies !
Simple Array Problem
I had this problem with arrays (can't remember what it was now) which went correct when using array(), but failed when using square-bracket syntax. It was something like this:

$arr['first level']['second level'][1] = 'bla'
$arr['first level']['second level'][2][ཇoneone'] = 'foo'
$arr['first level']['second level'][2]['bar'] = false;

Why doesn't that work. and does the following?

$arr = array(
'first level' => array(
'second level' => array(
1 => 'bla',
2 => array(
ཇoneone' => 'foo',
'bar' => false
)
)
);

View Replies !
Simple Associative Array
Here's my problem: I have a list of ~2,000 email addresses from subscribers in a flat file on disk. Due to the newsletter being personalized per domain, I'd like to read the entire file into a structure like this:

aol.com->[sherrij, foobar]
mindspring.net->[tom111, t23s,13223]
lycos.com->[dog,cat,tree]

where the index (key?) of the array is the domain, and it points to another array of actual user names.

my thought process is that i could use array_key_exists to search the array for an existing domain; if it exists, i'll then push it onto the array the domain points to.

View Replies !
Simple Split To Array
Code:

function extractdate($myrow) {
$datearray = array();
$datearray = split(' ',$myrow);
return($datearray);
}
*/
this should return an array
Monday
28
January
/*
$myrow = "Monday 28 January"

View Replies !
Array To Simple Variables Assignment
Am I conflating PHP with another language (PERL maybe?) or can you do an
assignment to $a, $b and $c something like ($a, $b, $c) = $array? The
given sytax doesn't work nor does [$a, $b, $c] = $array. This leads me
to believe in the conflation theory. If there is a syntax for this,

View Replies !
Bind Variables To A Simple Array
I'm very new to php. In my current code I'd like to bind variables to the
values of a simply (only indexed by numbers [s.
http://www.php-center.de/en-html-ma...pes.array.html]) array.
Of course I noticed the function extract(), but this works on string
indices. So I had the following idea:

<?PHP

function abind($array, $names) {
// Return source binding the given $names to the elements
// of the simple/linear array $array.
$r = "";
for ($i = 0; $i < count($names); $i++) {
$r = $r."$".current($names)." = $".$array."[".$i."];";
next($names);
}
return $r;
}

function test($arr) {
// create bindings for $foo, $bar and $baz by evaluating "$foo =
$arr[0]; ..."
eval(abind("arr", array("foo", "bar", "baz")));
return $foo."-".$bar."-".$baz;
}

echo test(array(1, 2, 3));

?>

Of course function test will use $foo, $bar and $baz really oftern. I could
as well use $arr[0] and so on, but I'd like to use more describing variable
names. In this case the eval line would make things more succint and thus
improve code readability.

Am I missing something? Is this a standard/idiomatic way in php or is there
some other?

View Replies !
Print Array Values (simple)
Would anyone know how to print just the values of the array separated by commas? So if I have an array,

$array = ("hello","to","you","there");

I would get

// hello, to, you, there

View Replies !
Add Image Id's To A Simple 1 Dimensionsal Array.
I have started a session, and I add image id's to a simple 1 dimensionsal array. nothing complicated. as the sql executes in a do while loop, I add the image IDs to the array. PHP Code:

//create array
$search_result_array = array () ;
//register session variable
$_SESSION['search_result_array'] = $search_result_array ;

PHP Code:

echo count($search_result_array) ;
.......

View Replies !
Simple Image Type Array Problem
Rather simple problem but I can't seem to get it solved. The second index of GetImageSize() just gives me integers which represent filetypes (i.e. 1 => GIF, 2 => JPG, etc.). What I want to do is create an array or somehow when I print $imagehw[2], the second index which displays the integers, I want it to display the filenames as opposed to the integer. Below I tried creating an array but all the output I get is, "array".

BTW, $id is defined previously.

I've tried php.net but I don't really understand their explanations and furthermore, nothing there really addresses my problems. The search here for previous posts on this subject resulted nothing significant.

Code:
<?php
$imagehw = GetImageSize("images/$id");
$imagewidth = $imagehw[0];
$imageheight = $imagehw[1];
$imagetype = $imagehw[2];
$imagetype = array (".gif"=>"1",
".jpg"=>"2",
".jpeg"=>"2",
".png"=>"3",
".swf"=>"4",
".psd"=>"5",
".bmp"=>"6");

print "<b>Filename</b>: $id<br>";
print "<b>Image Filetype</b>: $imagetype<br>";
print "<b>Image Width</b>: $imagewidth<br>";
print "<b>Image Height</b>: $imageheight<br>";

?>

View Replies !
Quikc Array Searching - In_array(array(),array())
Is it possible to quickly search array values from another array? I'm using this to make a quick dynamic menu include. But it tests false. Code:

View Replies !
Assigning A Multi-dimensional Array To & From A Session Variable Loses The Array
I have created a multidimensional array and then assigned that array to a session variable so that I can use it easily on another page.  However, when I go to the array later, there's never anything in it. Code:

View Replies !
Check If The Dates In The Array $holi[] Matches $evalday (not In An Array)
What I'm trying to do is check if the dates in the array $holi[]
matches $evalday (not in an array)
but with limited success the data in the array is:

$holi[1] = 2006-06-20;
$holi[2] = 2006-06-28;
$holi[3] = 2006-07-19;
$holi[4] = 2008-06-24;
$holi[5] = 2006-06-30;

$evalday = date("Y-m-d", strtotime("+ 1 days");

if($evalday == $holi) {
echo("For the purpose of this excercise, $evalday is a holiday");
}

View Replies !
Selecting Array Rows Based On An Array Of Field=>values
Here's the code i have:

$db = array(); //main array
$db['main'] = array(); //table `main`
$db['main'][] = array('id'=>0,
'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin');
//row
$db['main'][] = array('id'=>1,
'username'=>'bob_smith','userpass'=>'psswrd','userlevel'=>'user');
//row

function trim_value(&$value){
$value = strtolower(trim($value));
}
function fdb_select($fields = "*", $table, $where = false, $limit =
false){
global $db;
$retv = $db[$table];

//LIMIT RESULTS TO FIELDS
if(strrpos($fields, ",") === false){$field=array($fields);}else{$field
= explode(",", $fields);};
array_walk($field, "trim_value");
$all_fields = array_keys($retv[0]);
if($fields == '*'|| is_null($fields)){$field = $all_fields;};
$field = array_uintersect($all_fields, $field, "strcasecmp");
$retvi = array();
foreach($retv as $num =$row){
foreach($row as $fname =$fvalue){
$fname1 = strtolower($fname);
if(in_array($fname1, $field)){
$retvi[$num][$fname]=$fvalue;
};
};
};
//DONE LIMITING TO FIELDS
if($where != false){

//UP TO HERE IT WORKS FINE
//LIMIT TO WHERE CLAUSE
$retvj = array();
foreach($retvi as $num =$row){
//IN THE ROW
foreach($where as $k =$v){
//IF ROW MEETS ALL REQUIREMENTS
if($row[$k] == $v){
$retvj[] = $retvi[$num]; //Keep that row
};
};
};
//DONE LIMITING TO WHERE CLAUSE
};
$retvi = (isset($retvj)) ? $retvj:$retvi;
//SEND A FINAL ASSOCIATIVE ARRAY
return $retvi;
};
print_r(fdb_select("*", "main", array('id'=>"1",
"username"=>"joshfrench")));

the previous code outputs this:

Array
(
[0] =Array
(
[id] =0
[username] =joshfrench
[userpass] =password
[userlevel] =admin
)

[1] =Array
(
[id] =1
[username] =bob_smith
[userpass] =psswrd
[userlevel] =user
)

)

View Replies !
Array Data Matches But Array Created In Loop Doesn't Work
I have the exact same data in two arrays, but only the array created
like so will work:

View Replies !
Multidimensional Array Syntaxt For Preg_split Array Using Submitted Textarea
I have two textarea's called textarea1 and textarea2.  What i did was use preg_split to split the textarea into seperate rows that i could use for analysis like so

$array = preg_split("/[
]?[
]/", $_POST['textarea2'], -1,PREG_SPLIT_NO_EMPTY);
$array2 = preg_split("/[
]?[
]/", $_POST['textarea1'], -1, PREG_SPLIT_NO_EMPTY);

then i used a function created for me by a nice guy on here called get_ending($filepath) which basically stripped off of each peice of text the "http://www" from every URL i put into the textareas

finishing off i wanted to create an array that would input an expression such as:

echo "<a href='$array[1]' target='_blank'><img src='$array2[1]' border='0'>";

into a text area on the next page.  ALL of this works, except that i dont know how to properly loop throught he array so it'll properly insert the text into the textarea on the next page.

For now, all it does is place the array information in the page, rather statically, i would like to run some kind of if then statement that says

"while $array has some kind of text in it, keep running this operation of echoing the following expression adding 1 to the end of the array number"  I hope that makes sense

Any ideas? Code:

View Replies !
Take The Entire Array And Apply The Htmlentities Function To Each Array Element
what I want to do is take the entire array and apply the htmlentities function to each array element. So here is what I am doing:

$result = $dbconn->query("select * from tablename");

while($case = fetch_array_html($result))

Here is the function:

function fetch_array_html($result)
{
$arr = mysql_fetch_array($result);
foreach($arr as $key=>$val)
{
$arr[$key] = htmlentities($val);
}
return $arr;
}

Here is the error I get: Warning: Invalid argument supplied for foreach() on line 129
What exactly am I doing wrong here? I can usually fix my own errors, but this one is dominating me.

View Replies !
Finding Elements Of An Array In Another Multi-dimensional Array
So I have 2 arrays:
one contains userids. It may look like:
user_id[0] =12,
user_id[1] =30,
user_id[2] =43

The other is a multi-dimensional array with fields like:
user_info [0] = Array
(
[user_id] =13
[user_flag] =1
[url] =http://www.example.com?index,0
)
user_info[1] =Array
{
Array
(
[user_id] =120
[user_flag] =1
[address] =1234 Main St, Anytown, USA
[url] =http://www.yahoo.com
)
user_info[2] =Array
{
Array
(
[user_id] =130
[user_flag] =1
[address] =134 Main St, Anytown, USA
[url] =http://www.google.com
)

View Replies !
Array Element Disappears And The Whole Array Collapses And Renumbers Itself
checkbox arrays do not hold their respective positions as do other field arrays that are established to store the contents of selected records. The problem is that when you "uncheck" one of the elements and then repost,

that array element disappears and the whole array collapses and renumbers itself with only the remaining "checked" ones -- simply useless when dealing with records in a table where all the field array elements should be in sync.

I consider it a bug -- why does the array have to collapse? Why can't it just hold a null value and keep its position? The only fix is to never hold checkbox values in an array. Store them in individual variables numbered like an array, then do an "eval" to retrieve the contents. Here's the whole thing in action: Code:

View Replies !
Sorting An Array Problem, (array/string Manipulation)
I have a function that I found on google, that goes through a directory and spits out a directory tree in an array, with arrays inside of arrays, and more and more arrays inside of arrays, depending on how many subdirectories are there.....

Here is a sample "directory tree" it spits out. My problem is wanting to be able to create a new array containing only the paths to all the subdirectories it finds from this array, so it is with array manipulation...

Not all paths are located in the topmost array's values, but some directories are within other subdirectories and so forth.. I'm stumped on how exactly to sort through this array, whether recursively or not to grab all the 'paths' in the array period. Code:

View Replies !
Sorting Sql Results In An Array Using Things Outside The Array To Sort Them?
I'm using PHP to connect to a database full of place names, and their associated post codes, latitude and longitude on the earth. A user types his or her post code into a form, plus a distance (in miles), and the script looks for other area codes (first half of the post code) within that distance.

I can do that fine, but the results are ordered alphabetically by postcode, and I want to order it by the distance. Problem here, is that the distance isn't part of the array taken from the database, it takes the latitude and longitude of the area it's on in the while loop, and calculates the distance between the user's post code and that one, but it's not part of the array, so I can't sort the array using it.

How can I sort it? Can I add the calculated distances to the array, and sort it using sort()? If yes, how do I add them to the array?

Here's the page, just to explain better what the script does: http://navimaker.org/ed/owain/results.php?postcode=gl15&distance=34
Mess around with the postcode and distance vars.

I'd put the source on here too but I'm doing all this over SSH and can't copy & paste very easily .

View Replies !
Accessing Array Values Inside A Multidimensional Array
I need to access a value which is inside in a multidimensional array...

Suppose there is a form and where I takes all the form values inside an array named access..and I post the values into a different array.

$registrationArray = $_POST['access'];

Now I need to loop through this registration array and get values printed to the new variables...

Suppose this is the array $access = array (fname,lname,date,year,month)

How do I print the date,year,month values into different variable by looping through registration array..

View Replies !
Add Variable Into An Existing Array, Storing The Array Into The Database
help with assigning id numbers to users within the database, being able to extract that id number into a variable, create new arrays, add that variable into an existing array, storing the array into the database, being able to call the database and display links pictures and text from the variables within arrays.

View Replies !
Opening Javascript File And Parsing Array Into Array
I'd like to open a .js file that contains a multi-dimensional array and parse it
into a PHP array. Code:

View Replies !
Trying To Compare Array Values To A Value, Then Create Boolean Array
I have an array that returns data like this (see array below) The array[0] contains all the votes for one story as well as information that pertains to that vote, and the array[1] contains vote information for another story. What I need to do is check is a user_id stored in a session, is in the array, and then create a boolean array from that.

For example, here I want to check if the user_id is featured in the first set of data, let's say my user_id is 74. Ok, so it is in the first set of data, so we set the boolean variable to true. Next I need to search the second data field for my user_id, 73. It is not featured here so the value in my array is set to 0.

I need an array that returns values either 1, for true, your user_id was found in the table, or false, for your user_id was not featured in the table. They need to be in order of the story too. I'm having trouble one comparing the two variables against eachother, since the array is very deep, and two, creating the array on the fly. Code:

View Replies !
Adding To $_POST Array Is Not Reflected In $_REQUEST Array
Recently I wrote this:

<? echo 'action = '.$_REQUEST['action'].'
'; ?>
<?php $_POST['action'] = 'newmember_split'; echo 'action = '.$_REQUEST['action'].'
'; ?>

My expected output was:

action =
action = newmember_split

However my output was:
action =
action =

How is this so. As far as I know $_REQUEST is supposed to reflect both $_POST and $_GET. I tried to find some information on it but failed.

View Replies !
Sort Array - [2] => Array( [id] => 232, [zone] => C, [color] => Yellow )
Array:

=> Array( [id] => 64, [zone] => a, [color] => blue )[1] => Array( [id] => 17, [zone] => b, [color] => grey )
    [2] => Array( [id] => 232, [zone] => c, [color] => yellow )
    [3] => Array( [id] => 36, [zone] => a, [color] => red )
    [4] => Array( [id] => 178, [zone] => a, [color] => white )
    [5] => Array( [id] => 10, [zone] => c, [color] => blue )
    [6] => Array( [id] => 115, [zone] => a, [color] => orange )
    [7] => Array( [id] => 345, [zone] => a, [color] => black )
    [8] => Array( [id] => 19, [zone] => b, [color] => green )
    [9] => Array( [id] => 206, [zone] => a, [color] => red )

View Replies !
Array Explode Problem Result In A 6 Item Array
I have the following:

$BB_Basket = "basket=¦APL6007,2.00¦AVX8900,1.00¦ARCAV500,1.00";
$basket_containers = explode('¦', $BB_Basket);
unset($basket_containers[0]);
print_r($basket_containers);

This results in

Array ( [1] => APL6007,2.00 [2] => AVX8900,1.00 [3] => ARCAV500,1.00 )

Now when I try to explode further with

$basket_items = explode(',', $basket_containers);
print_r($basket_items);

This results in

Array ( [0] => Array )

This should result in a 6 item array. Any ideas what I'm doing wrong?

View Replies !
2D Array - Count The Size Of Each Array Element
What i want is something like

for ($i=0;$i<$var;$i++) {
create 2D array
if (condition) {
push element in array //
}
}

ie..1=>a,b,c,d
2=>e,f,g
etc
then i want to count the size of each array element

eg. for array1 : no of elements 4
for array2 : no of elements 3
etc

Not done 2D arrays before.

View Replies !
Array Checking For Page Content In A Array
i am using a function which gets all the links from a page, from that i have a function that gathers the html in the page from each links..this part works great..

i then need to check and see if it has a applet, flashmovie etc tag in the page. if there is a tag like this in the page ineed to return true if there isnt i need to return false

i have provided code thats shows how i gather the links echo them out and checks to see if certain html tags are in a page using a function


$snoopy->fetchlinks($url);
$results=$snoopy->results;
$results=array_unique($results);
sort($results);
for($i=0;$i < $numberoflinks; $i++)
{
$results[$i] = preg_replace( "/(?<!")((http|ftp)+(s)?://[^<>s]+)/i", "", $results[$i] );
if ($results[$i] == '')
{
}
else
{
?>
<a href="index.php?mode=2&url=<? echo $url.$results[$i];?>"><? echo $results[$i];?></a>
<?
$snoopy->fetchform("$url.$results[$i]");
$test=$snoopy->results;
/
if($test != "")
{
echo "problems seen<br>";
}else{
echo "no problems<br>";
}
}
}

View Replies !
Array Sorting Blues....2 Dimensional Array
I have a 2 dimensional array where one col contains a Unix style date and the other contains a filename. I read through a directory to get this info. I can load the array and print it out just fine, but I can't seem to sort it using any of the sort functions! I want to reverse sort them, since they are news stories that I want to display in the correct order by date. When I try to sort I get a "Warning: Cannot compare arrays or objects" message. I have the feeling it's something stupid on my part but can't find any good examples anywhere.

Anyone have an idea about this?

P.S. I know a database would solve this but sadly it's not an option for me right now...

View Replies !
Turn Array Into Multi-dimensional Array?
How can I take an existing array and turn it into a multi-dimensional array? I want to get a single row out of a MySQL table and have it in an array, but have along side the values the true field (column) length for each of the fields from the table. Here's my stab at it:

$userDetails = mysql_fetch_array($resultID);
$i = 0;
while ($i < mysql_num_fields($resultID))
{
    $userDetails[$i][2] = mysql_field_len($resultID, $i);
    $i++;
}

And I guess the follow up question (if this is indeed possible) is will this work with a multi-row return from the DB also?

View Replies !
Setting Variable To Array Within Mysql_query() Array
I found your site while attempting to solve the problem of utilizing JOIN statements in a PhP mysql_query. Your timely and well-structured assistance to LemonFizz was very helpful, and enabled me to develop the query below.

I have now queried multiple tables to produce an associative array of all of a particular student's data after selecting the student's unique ID from a drop-down. This required the use of JOIN statements in my query. The query section of the file is as follows:

View Replies !
Create Array From Members Of An Array Of Objects
I have the following situation:

$list[] is an array of MyElement objects.

MyElement has two members: MyElement->member1; MyElement->member2;

What I want is to get the following:

$newlist[] so that:

$newlist[0]=$list[0]->member2;
$newlist[1]=$list[1]->member2;
$newlist[2]=$list[2]->member2;
....

I need to do this using A SINGLE LINE OF CODE.
Is it possible? How to do this?

I tried with:

array_walk($list,create_function('$a,$b,$result',' $result[] =
$a->member2;'), &$result);

but I get the following error:

Warning: Call-time pass-by-reference has been deprecated - argument
passed by value; If you would like to pass it by reference, modify the
declaration of array_walk(). If you would like to enable call-time
pass-by-reference, you can set allow_call_time_pass_reference to true in
your INI file. However, future versions may not support this any longer.

View Replies !
Trying To Calculate An Average Array From An 2d Data Array
I'm trying to calculate an average array from an 2d data array.
my problem is that my function does not generate an average array but just
one value. but i do not understand why it does not work.

code:
-----
function calculateAverageRating($rating_matrix)
{
$average_rating = array();
foreach($rating_matrix as $cus_id => $ratings)
{
$counter = 0;
$sum = 0;
foreach($ratings as $pro_id => $item_rate)
{
$counter++;
$sum += $item_rate;
}
echo $cus_id."->".($sum/$counter)."<br>";
$average_rating[$cus_id] = ($sum / $counter);
}
echo "<hr>";
echo "<table> <tr>";
foreach($average_rating as $key => $value);
{
echo "<td>$key::$value</td>";
}
echo "</tr></table>";
return $average_rating;
}

wanted:

input -> output

1 1 1 1
2 2 2 2
4 4 4 4

but my functions just does:

input -> output

1 1 1
2 2 2
4 4 4 4

View Replies !
Modifying Values In An Array And Then Putting Them In A New Array
How do i get values out of an array, modify them and then put them back into a new array.
I have tried using a foreach to get the values out and to edit them but i don't know how to get them into a new array. Here's the code:

View Replies !
Passing Array Of Multidimensional Array To Function
How do I pass a part of a multidimensional array to a function. I have the following (in pseudo):

$arrays[m][n]; // filled with values
$chosen = 3;

function doSomething($array) {
 // do something with 1D array
}

This fails:

doSomething($arrays[$chosen]);

Can someone explain to me why? And how to do this right?

View Replies !
Explode Array Created An Automatic Key For Each Row In The Array.
I have a string, like this:

Userid1 Pass1
Userid2 Pass2
Userid3 Pass3
Userid4 Pass4

Each column is tab separated. I want to explode it into an array so that the userid will be the key, and the password the value. I tried to do it like this:

$array = explode(" ", $string); // Where $string is the string above.

However, this returned both the userid and the password as the value, and created an automatic key for each row in the array.

View Replies !
Searching An Array - Search The Second One With The First Ones Array Keys?
I've been banging my head against this one for awhile. One array has numbers like awz001 for keys and the count of how many times they appear as values. There's about 300 key, value pairs in this array. So

Array = ([awz001] => 7, etc...)

and the other array is a multi-dimensional

Array ( [0] => Array ( [number] => awz001 [0] => awz001 [Section] => Section one [1] => Section one )

Is there away to search the second one with the first ones array keys? Would you do it with two loops? First through the multi then the single?

View Replies !
Show Array Of Array Of Array Of Array...
I'm trying to print an array of (datas and array of (datas and array of
(datas and array.....

Here is the code:

View Replies !
Sort The Array By The Values In Array[$i][0]
How would I go about sorting the following array, I've been looking at array_multisort but to be honest I'm either not fully understanding it or it's not capable of what I'm trying to do.

What I'd like to do is to sort the array by the values in array[$i][0] but I can't figure it out, the values being zzzz,a0,a1,00000000000000. PHP Code:

View Replies !
Getting Array Information Out Of A Function On Into Another Array
I need to find a way to transfer all the values of an array inside a
function out of the fuction into another array. IE

function splice($filename){
if(file_exists($filename)){
$value=array("0"); // clear the array.
$rows=file($filename); // break text file into a rows array
for($num=0;$num < count($rows); ++$num){
$column=split(";",$rows[$num]);
$value[$num]=$column;}}
return $value;
}

$array1 = splice(file.txt)


Example file data would be

data1;an1;bc1
data2;an2;bc2
data3;an3;bc3

View Replies !
Creating An Array Of Two Elements From Another Array
I’m trying to create an array that contains a department name and a associated colour code, by filtering from a SQL result. I’ve written a simple script, but to be honest I’m now stumped how to create such an array. PHP Code:

View Replies !
Set An Array Of Array, Do An Unset And Display Both
see this code, i only set an array of array, then i copy this array in
another one, do an unset and display both:

$a["row1"]=array("row1.1"=>"row1.1.1"
, "row1.2"=>"row1.2.1");
$a["row2"] = array("row2.1"=>"row2.1.1",
"row2.2"=>"row2.2.1");
print_r($a);
$temp=$a;
unset ($temp["row2"]["row2.1"]);
print_r($temp);
print_r($a);

it works as expected, the unset within $temp does not affect rows within $a.

BUT, if you replace $a=>$_SESSION, the unset within $temp do the same thing
within $_SESSION!!
The row is unset within $temp AND $_SESSION!!

How do you explain that?

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved