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




Array Keys


Been trying to figure out an array issue.  For some reason when I echo $key it's echoing "Array".  I want it to return the key (in this case adventure). Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Using Array_intersect() Without Keeyping Keys From The Array1, I.e. Re-number Intersect Array Keys.
I only use indexed arrays.

When I use array_intersect function, of $a3 = array_intersect( $a1,
$a2 ), I just need the vales of intersect array and let keys to be
re-numberred from 0.;

I found the intersect array $a3 have the correct values but keep the
keys of $a1. When I use
for loop from $index=0 to sizeof ($a3)-1, by $a3[$index], php reports
"undefined offset " problem.

How can I re-number the keys of $a3 from 0 to sizeof($a3)-1;



Using Max() On Array Keys
i am using an array to store contact data within a session. it looks like this:

$_SESSION['contact'][$key][<content>]

$key counts the set of records, so i have

$_SESSION['contact'][&#390;']
$_SESSION['contact'][&#391;']
$_SESSION['contact'][&#392;']

and so forth. [<content>] stands for the fields containing the actual set of data, which are stored within the [$key]-arrays. at one point i need to find out what the highest value of $key is. running max($_SESSION['contact'])

simply leaves me with "Array()" as the result. what i am doing wrong, and how do i correct it?

Array Keys
is it possible to use only a key in an array meaning:

$arr["a"]="yo";
$arr["bc"]="ygo";
$arr["eea"]="wgyo";
$arr["fa"];
$arr["a"]="yo";

and then somehow get all the keys without and value i tried:

while (list ($key) = each ($arr)) {print $key;}

but i doens't seem to work.

Array Keys
If I used a "for each" to go through an array or irregularly numbed keys, is there a way to get the key number that the loop is currently on each time?

Automatic Array Keys
My array keys are behaving strangely. In the manual it says calling an array like $array[] = "something" should make the value be put into the next available integer key available. However, my values are being placed with whole sets of blank keys inbetween. Here's what part of the print_r() of the array returns: Code:

Print Out Array Keys Only
Hi, there are lots of examples that show you how to print array values
given a key. Do you know how to print keys for a given array.

example

$myArray = array('a'=>1, 'b'=>2, 'c'=>3, 'd'=>4);

How do you print 'a', 'b', 'c','d' only without using any loops?

Printing Out Array Keys
i'm trying to find a simple way of printing out the keys in an array
generated by mysql_fetch_array which returns a single row.

i.e.

while ($row=mysql_fetch_array($result) )
{

print out the $row keys and values

}

is this possible?

Write Array Keys To SQL
I have an array of data. I want to write each key in the array to its own row in SQL. what would be the best way to accomplish this?

Trouble With Moving Keys In An Array
OK i have the following array......

Foreach Loop With Array Keys
I am unable to get the following piece of code to work as
desired. The fields valuable seems to contain all values however the
vaules variable only contains the first assignied with

$values = ''' .
$arry[$keys[0]] . '''
$keys = array_keys($arry);
$fields = '`' . $keys[0] . '`'
$values = ''' . $arry[$keys[0]] . '''
foreach($keys as $key)
{
if($key != $keys[0]) {
$fields .= ', `' . $key . '`'
$vaules .= ', '' . $arry[$key] . '''
}
}

Prepend Array Keys With A String
I have looked on uk.php.net for the function I need but can't find it. Does anyone know what the function is called who's purpose is: to recurse through an array and assign values to keys whilst prepending the key name with a string specified by one of the function parameters?

Getting Deep Array Value Without Knowing Keys?
I've racked my brain for the last few hours trying to figure
this one out. I have an array of language strings such as :

$lang = array();
$lang['en']['prompt']['hello'] = 'hello'
$lang['en']['prompt']['bye'] = 'goodbye'
$lang['en']['number']['first'] = &#391;st'

This is being used by an ajax routine, so I don't know which string
will be requested at runtime. So, I've got $lang and a request
('en_prompt_hello'), and tried a few things such as:

$request = explode ($request);
$found_string = array_intersect_assoc ($lang, $request);

to no avail. Short of having to do a complicated recursion searching
at every available depth, is there an easy way to do this?

Multibyte Strings As Array Keys
Does this work? Something is breaking when I try to do this, and all I
can think of is that PHP does not allow multibyte array keys.

Sort An Array Using 2nd Dimension Keys
I need to sort an array (configured as shown) based on one of the second dimension keys.

[1] ['File_Name'] => test.doc;
[1] ['File_Type'] => MS Word;
[1]['Size'] => 50;
       
[2]['File_Name'] => test.pdf;
[2]['File_Type'] => Adobe PDF
[2]['Size'] => 150

[3]['File_Name'] => test.xls;
[4]['File_Type'] => MS Excel;
[5]['Size'] => 60;

For example, I'd like the order of the 1st dimension keys (integer indices) to reflect the order if the array is sorted by the "File_Type" key.

CLI- Reorder Array Keys After Using 'unset'
I'm having a problem finding a sort function that will reorder the keys in an array after I delete one of the array key/value pair. So if I have array: Code:

Argument To Keys() Should Be An Array In Main.inc On Line 152
I am getting the following errors:

Warning: Argument to keys() should be an array in main.inc on line 152

Warning: Non array argument supplied for foreach() in main.inc on line 152


I've developed the site on my linux box at home using PHP 4.0.3pl1. It works great, but when I upload it to my hosting service I get the above messages. I've tried all the different ways to go through an associative array. I've tried doing an implode(array_keys($arr), ',') then split on ','. It keeps coming back to the fact that it doesn't recognize the array I declare right before it is an array.

The hosting service runs a BSD Bosx and uses PHP 4.0b2. I'm wondering if this was a problem with the second beta release or if it is something screwy between platforms.

Why does it work great on my box but when I upload it it craps out?

Manipulate Array Keys And Values For Query String
i'm creating a function where I can update my records ... but it doesnt work...I echoed my SQL query and it turned fine..but it didnt update my record! PHP Code:

Getting Keys/values From POST Array In An Orderly Fashion..
I've got this javascript that results in the following being posted;

weight_1 = 30
cost_1 = 20
amount_1 = 32

weight_3 = 65
cost_3 = 23
amount_3 = 12

weight_7 = 43
cost_7 = 9
amount_7 = 12

etc.., with the numbers appended to the keys (here 1, 3, and 7) ascending but not sequential.

I need my PHP recieving these POST keys/values to present them like this:

#1
Weight: 30  Cost: 20  Amount: 30

#2
Weight: 65  Cost: 23  Amount: 12

#1
Weight: 43  Cost: 9  Amount: 12

Whats' the right way to do this?
I've been messing around with array functions but haven't quite figured out which to use..

Primary Keys
How is it that even though I have the column "username" in my database set
as a Primary key, using my PHP script to add new users to the database works
without any errors even when signing up using an existing username. I have a
database full of the same usernames!

Shortcut Keys
I would be liek to be able to set up a webpage with shortcut keys so that when certain buttons are presses, a pop up window will open with a designated further page displayed.  Specifically I would like the shortcut keys to be a couple of the function keys, ie f10, f11 and f12. 

PHP & MySQ + Unique Keys
I'm trying to write a system thats used for about 50 clients that uses html
forms and php to log details. The problem is that when a client loads the
form page it's given a value which is the last record in a table +1 (i.e. so
its the next record). The problem with that is that a client could sit on
that page for 20 mins (or whatever length of time) and a different client
could use that record number and there what be an error "duplicate key....".
I could use an MySQL UPDATE to lock the record when its issued to each
client and maybe use a timestamp and check if the timestamp is over 10 mins
and delete any records that are over 10mins but there is the possibility of
redundant data (or really useless data, a unique record and a timestamp) in
the table sitting there for 10mins at a time.

Is there an easy way of 'gauranteeing' a client a unique key? So you don't
have to lock the record when the page loads (this also means that when you
refresh the page that the unique key is incremented as you locked the last
record and didn't put anything into the table, so the refreshed page is
issued the next key +1 again).

Associative Arrays Keys
I have a some text that i have to sort according to their year. The text is in this format..

A Short Story (2000)
A long time ago (1999)
A list (2004)
Before Time (1999)
Car parts (2004)

so basically i want the output to be..

A long time ago (1999)
Before Time (1999)
A Short Story (2000)
A list (2004)
Car parts (2004)

I thought the way to go about this would be to extract the years and put the whole thing in an associative array with the years as keys, but of course the keys have to be unique so in this case values override each other. PHP Code:

Getting MySQL Generated Keys
I am a Java/JSP developer by trade but am currently developing a
MySQL/PHP solution.

In JSP when I run an INSERT statement on the db I am able to
automatically get back a list of any generated keys (without having to
do some sort of subsequent query to get the information).

Is there a PHP equivilent of this?

ActiveRecord And Foreign Keys
I am having trouble wrapping my mind around the ActiveRecord pattern and
foreign keys.

I understand that for each table, there should be a class, and each row
is is effectively an instance.

But, my problem arises when I look at foreign keys and advanced
relationships. For basic foreign keys, I can just automatically
reference to the object. Example:

Table: invoice
id, notes

Table: items
id, cost, invoice_id

When working with an instance with items, I can easily load a new object
called "invoice."

But, what if I am already working with invoice, and I want to load
items? I can't think of any way to abstractly relate the two.

Also, what if I want to two things that are both a "has many"
relationship? For example, if I take users that can have multiple
qualities, I would need three tables: one for users, one for the
qualities, and one to link.

Table: users
id, username

Table: link
id, user_id, quality_id

table: qualities
id, quality_name

PHP MYSQL And Primary Keys
Say I have an ID field in my database that is a primary key and an UNSIGNED AUTO INCREMENTING TINYINT.

It stores range of 0-255. Ok I add a few items to the database, say 240. At a later date I delete a few records, say rows 33, 44, 55, 66, 77, and 240.

So the last record in the database now has an ID of 239, I add another record and it gets assigned an ID of 241?. I then add a few more and it finally reaches ID 255. Now all the ones I deleted previously do not exist. So I try to add another record, will it just get added and assigned the ID of a record that doesent exist such as 33, 44, 55, 66, 77 or 240? If not is there a way around this?

I am pretty new to MySQL and I dont know the answer to this but I know that it could prove to be pretty inefficient if an ID field can hold 255 records but only holds 240. Do you understand what I mean and can anyone answer my question?

Foreach Is Returning Value Of First Key For All Keys
I'm having trouble with the foreach function. I'm using it twice
inside a user defined function with two different arrays, and in the
second instance it's returning the value of the first key for all the
keys. My code is shown below and the problem areas are marked with
comments. In case you're wondering, this script is for generating
sticky checkboxes that include an event handler.

<form>

<?php

if (! is_array($like)) { $like = array(); }

function make_checkbox_click ($name, $query, $options, $onClick) {
foreach ($options as $value => $label) {
printf('<label><input type="checkbox" name="%s[]" value="%s" ',
$name, $value);

# This is the instance of foreach that's not working correctly.
# It's returning the value of the first key for all the keys.

foreach ($onClick as $key => $event) {
printf ('onClick="%s" ', $event);
}

if (in_array($value, $query)) { echo "checked "; }
echo "/> $label</label><br />
";
}
}

# End of user defined function.

$characteristics = array(
'personality' => ' I love their personalities.',
'minds' => ' I admire their minds.',
);

# This is the array that foreach isn't working correctly with.

$charClick = array (
'personality' => "alert('Aren't they the greatest?');",
'minds' => "alert('They're smarter than most people their age.');",
);

make_checkbox_click (posPoints, $posPoints, $characteristics,
$charClick);

?>

</form>

Mysql: Get Foreign Keys
there is a function to get the foreign keys of a table?

i have this function to get all table infos:
$fields = mysql_list_fields($V['db']['name'],$table) or die
(mysql_error());
$columnsCount= mysql_num_fields($fields) or die (mysql_error());
for ($i = 0; $i < $columnsCount; $i++) {

$columns[$i]['name']=mysql_field_name($fields, $i) ;
$columns[$i]['length']=mysql_field_len($fields, $i) ;
$columns[$i]['type']=mysql_field_type($fields, $i) ;
$columns[$i]['flags']=mysql_field_flags($fields, $i);
}

but i need alo to know info about foreign keys.

How To Disable Controle Keys
In my application I want to disable my controle keys to
save copying and taking screen shots of the my page.

Associative Arrays: Are Keys Strings?
I am wondering if it is 'wrong' (although it works) to work with associative arrays like this:

$array[somekey] = blah

instead of specifying the key as a string:

$array["somekey"] = blah

What would you say? What is right, what is wrong from the point of view of correct PHP coding?

Getting Data For Duplicate Keys In $_POST
I'm trying to process a form that I got from a JSP generated page.
Basically, want to take out and process some of the data, and redirect the
rest to a JSP page that will handle the rest. All works well, i traverse
$_POST, writeout hidden input fields and autosubmit the form with a little
javascript, a perfectly acceptable solution for our users.

However, the data the JSP page sends contains one certain input with the
same name a couple of times. Due to complicated reasons, I cannot change
that name into a PHP-style array. PHP, however, throws all the values of
those fields away except for the last one.

Is there any way to retreive data from inputs with duplicate names? I know
that with GET, I could just parse the query string myself, but sadly i need
to use $_POST (the thing I'm processing in PHP is a file upload). I have no
way of changing the input names themselves (and see no alternative other
than pulling a lot of ugly javascript hacks in the JSP page to fake it all).

$_POST + Spaces And Dots In Keys
I have a very strange behaviour with POST keys.

Consider a test:

wtf.html:

=== Cut ===
<form action="eh.php" method="POST">
* * <input type="checkbox" name="many spaces and. . dots. . "/>
* * <input type="submit" value="Submit">
</form>
=== Cut ===

eh.php:

=== Cut ===
<?php
* * print_r($_POST);
?>
=== Cut ===

When we check the checkbox and click the Sumbit button we will see:

Array ( [many_spaces_and____dots____] => on )

It is send to server normally:

many+spaces+and.+.+dots.+.+=on

but in $_POST (or $HTTP_POST_VARS)

Foreign Keys Search Type
I have an sql db that I need to create a search page for.  I have used phpmyadmin to extract the entire table set up out.  The file it created is attached.

What i am trying to do is to create a search page that will retun the resutls of a search.  The only parameters that need to be searched are company, position or country.  Any or all of these can be search at the same time to produce a result.  Teh results need to be in a line by line format that when clicked on will show a second page with all teh details from the db.

Insert And Auto Incrementing Primary Keys
I am using MySQL and PHP. What I am trying to do is use a form to start a new record in a db. I am using an auto_incrementing field as my primary key. Right after I insert the record I want to get the value of the primary key so I can display a second form that will ask for more information. Is there a way to determine what the auto_incrementing field was set to after doing an insert?

Clearing A Table's Primary Keys In MySQL
This may be a silly question, but is there a way to clear out primary key's in a table so that the next entry starts over at 1 again?

We have a database that we have done a lot of testing in, and now that we want to go live we would like to have all the keys start at 1.

Do I have to drop and recreate all the tables or is there a way to do this via a command?

[ot] Listing Foreign Keys In MySQL On InnoDB
I use mysql 5 with innodb engine.
When I create a table like:
create table tbltest(
testid int(10) UNSIGNED NOT NULL auto_increment,
artid int(10) UNSIGNED NOT NULL REFERENCES tblart.artid,
PRIMARY KEY (testid)
) ENGINE=InnoDB;

Works fine.
If I insert a value in artid that doesn't exist in tblart, mysql produces an
error as it should do.

Now if I want to find out about the tablestructure, like this:
SHOW CREATE TABLE tbltest;
mysql just shows the create table syntax, BUT without the FK-constraint.

When looking through the documentation I only found SHOW TRIGGERS, but that
also doesn't list the FKs.

I must be missing something completely in the docs. :-/
How can I ask mysql which Foriegn Keys it has?

PHP Encrypt/Decrypt Whith Asymetrics Keys
I have generated two keys :
"C:>openssl req -nodes -new -x509 -keyout ben.key -out ben.crt -days
3650"
I try to encrypt/decrypt a string like "JOHN" with these asymetrics
keys. With the following code, it works.
I encrypt with the public key which is in the certificate.
I decrypt with the private key.
But why, the crypted message is different every time I start the
programm...?
__________________________________________________ _______
<?php
echo "---CRYPT---<BR>";
$source="JOHN";
echo "Message : $source<BR>";
$fp=fopen("./ben.crt","r");
$pub_key=fread ($fp,8192);
fclose($fp);
//echo $pub_key;
openssl_get_publickey($pub_key);
openssl_public_encrypt ($source,$sourcecrypt,$pub_key);
echo "Crypted message : ".$sourcecrypt."<BR><BR>";
$source="";

echo "---DECRYPT---<BR>";
echo "Crypted message : ".$sourcecrypt."<BR>";
$fp=fopen("./ben.key","r");
$priv_key=fread ($fp,8192);
fclose($fp);
$res=openssl_get_privatekey($priv_key);
openssl_private_decrypt ($sourcecrypt,$newsource,$res);
echo "Source decryptée : $newsource<BR><BR>";
?>
__________________________________________________ _________

Now here is my second question :
In fact I encrypt with a java programm where is my certificate and I
decrypt with a PHP programm like I've just explane before.

__________________________________________________ _________
public String crypt(String message) {

//Cert is in LDAP
Certificate cert =
userProvider.getUserCertificate(getCurrentUsername ());

PublicKey publicKey = cert.getPublicKey();

try{
Provider secProvider = Security.getProvider("BC");
if (secProvider == null) {
secProvider = new BouncyCastleProvider();
Security.addProvider(secProvider);
}
Cipher encryptCipher = Cipher.getInstance("RSA", secProvider);
encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);

//Crypt...
String resultCrypt = new String();
byte[] messageBytes = message.getBytes();
byte[] resultCryptBytes = encryptCipher.doFinal(messageBytes);
resultCrypt = arr2str(resultCryptBytes);

return resultCrypt ;

}catch(Exception e){
//throw ...
}
}
__________________________________________________ ______________

Why my programm PHP can't decrypt the message? I use evidently the
correct private key which corresponds with the public key.

Explicit Numeric Keys Vs Item Position
Say if I have a mixed array:

$array = array("item1", "2"=>"item2", "5", "item4key"=>"item4")

Is it possible while looping through the array (foreach ($array as
$key=>$val)) to check if an item has an explicit key specified instead
of its automatically assigned position key?

One Result Set Makes Two Lists With Same Keys And Values
I have a page with two drop-downs, each listing the same employee names
and their id's as the values. So they look like:
<select name="selection_1">
<option value="12">Curly</option>
<option value="8">Larry</option>
<option value="36">Moe</option>
</select>

....then further down the page:

<select name="selection_2">
<option value="12">Curly</option>
<option value="8">Larry</option>
<option value="36">Moe</option>
</select>

Currently I am doing this, which works but seems sloppy:

<select name="selection_1">
<?
while($employees=mysql_fetch_assoc($qry_rslt)) {
/* ADD NAMES TO DROPDOWN WITH emp_id's AS THEIR VALUES */
?><option
value="<?=$employees['emp_id']?>"><?=$employees['name']?></option><?

/* CREATE ANOTHER ARRAY WITH THE emp_id AS THE KEY */
$emp_list_2[$employees['emp_id']]=$employees['name'];
}
?>
</select>

Then on the second drop-down:

<select name="selection_2">
<?
foreach($emp_list_2 as $key => $emps) {
?>
<option value="<?=$key?>"><?=$emps?></option>
<?
}
?>
</select>

Using Keys And Sessions To Bypass Secure Directory
I have a Pay Pal "buy now" button on my website, when the customer goes to Pay Pal to make a payment, they are then redirected to a certain page on my site. I have secured the my directory so that no one can just type in the URL?

I do however, want the customer to be able to bypass that secure login when they are redirected from Pay Pal.  I know I can use keys and sessions to pass the username and password but I'm unclear on how this works. 

Generating Unique Primary Keys For MySQL With PHP (overkill)
I'm looking at some of my MySQL databases that rely on auto-incremented serial numbers for primary keys and I've decided it's time to come up with a better way as my projects are becoming increasingly complex.

I wouldn't want to be in the position of writing a solution that used up the 32,768 keys per month their SMALLINT serial number generator (just a guess) was producing and left thousands of customers stranded on Christmas day. [story]

I've put this function together that (as shown) has 3636 possible keys, or a little over 1.46 quindecillion. (It scales easily to smaller or longer keys.)

function produceFib($length) {
$val = ''
for($i=0;$i<$length;$i++) {
$str = 'abcdefghijklmnopqrstuvwxyz0123456789'
$shuffled = str_shuffle($str);
$val .= substr($shuffled, 0, 1);
}
return $val;
}
echo produceFib(36);

So here's my questions:
- Is this overkill?
- Do I need to do something more complex?
- How do you do it?

$result = $stmnt->fetchAll(); Returning Duplicate Keys For A Single Query
For some reason when I do a fetchall on a PDO query the array returned
has duplicated keys. see below.

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:

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
)

)

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:

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:

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
)

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:

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 .

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>";
}
}
}


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