Re: [PHP] Array help.

2012-10-24 Thread Paul Halliday
On Wed, Oct 24, 2012 at 2:40 PM, Samuel Lopes Grigolato
samuel.grigol...@gmail.com wrote:
 Could you try changing this:

 if($groupTest != FALSE) {

 to this:

 if($groupTest !== FALSE) {

 ?

Hah. Perfect! Thanks.


 -Mensagem original-
 De: Paul Halliday [mailto:paul.halli...@gmail.com]
 Enviada em: quarta-feira, 24 de outubro de 2012 15:38
 Para: PHP-General
 Assunto: [PHP] Array help.

 I am processing v4IP's and what I want to do is a prefix substitution if the
 3rd octet matches a predefined list $groupMappings. I went down this  path
 and it isn't working as expected. Drawing a blank on this one. Why does 40
 miss the comparison?

 $hostname = Z;
 $ips = array('10.1.40.1','10.1.41.1','10.1.1.1','10.1.40.1','10.9.1.1');

 foreach ($ips as $ip) {

 $groupMappings = array('40' ='A','41' ='B','1' ='C');

 $ocTest = explode(., $ip);
 $groupKeys = array_keys($groupMappings);
 $groupTest = array_search($ocTest[2], $groupKeys);

 if($groupTest != FALSE) {
 $hostGroup = $groupMappings[$groupKeys[$groupTest]];
 echo Hit! $ip : $hostname : $hostGroup\n;
 } else {
 $hostGroup = substr($hostname, 0,2);
 echo Miss! $ip : $hostname : $hostGroup\n;
 }
 }

 Miss! 10.1.40.1 : Z : Z
 Hit! 10.1.41.1 : Z : B
 Hit! 10.1.1.1 : Z : C
 Miss! 10.1.40.1 : Z : Z
 Hit! 10.9.1.1 : Z : C

 Thanks!

 --
 Paul Halliday
 http://www.pintumbler.org/

 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
 http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Array help.

2012-10-24 Thread Ford, Mike
 From: Paul Halliday [paul.halli...@gmail.com]
 Sent: 24 October 2012 18:38
 To: PHP-General
 Subject: [PHP] Array help.
 
 $groupMappings = array('40' ='A','41' ='B','1' ='C');
 
 $ocTest = explode(., $ip);
 $groupKeys = array_keys($groupMappings);
 $groupTest = array_search($ocTest[2], $groupKeys);
 
 if($groupTest != FALSE) {

I think you're making a little bit of a meal of this. My initial thoughts
included pointing you at array_key_exists() (and, why on earth
have you got $ocTest[2] in quotes?), but then I realised if I were
writing this I'd probably just use isset(), thus:

   $ocTest = explode(., $ip);
   if (isset($groupMappings[$ocTest[2]])):
  // success
   else:
  // fail
   endif;

Hope this helps!


Cheers!

Mike

-- 
Mike Ford, Electronic Information Developer, Libraries and Learning Information
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS, LS1 3HE, United Kingdom
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730

To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help.

2010-07-30 Thread Joshua Kehn

On Jul 30, 2010, at 2:36 PM, Paul Halliday wrote:

 I have a query that may not always return a result for a value, I need
 to reflect this with a 0. I am trying to overcome this by doing this
 (the keys are ID's):
 
 while ($row = mysql_fetch_row($statusQuery)) {
 
$cat = 
 array(0=0,1=0,11=0,12=0,13=0,14=0,15=0,16=0,17=0,19=0);
 
switch ($row[1]) {
case 0: $cat[0] = $row[0]; break;
case 1: $cat[1] = $row[0]; break;
case 11: $cat[11] = $row[0]; break;
case 12: $cat[12] = $row[0]; break;
case 13: $cat[13] = $row[0]; break;
case 14: $cat[14] = $row[0]; break;
case 15: $cat[15] = $row[0]; break;
case 16: $cat[16] = $row[0]; break;
case 17: $cat[17] = $row[0]; break;
case 19: $cat[19] = $row[0]; break;
}
 
print_r($cat);
}
 
 Which gives me this:
 
 Array ( [0] = 15547 [1] = 0 [11] = 0 [12] = 0 [13] = 0 [14] = 0
 [15] = 0 [16] = 0 [17] = 0 [19] = 0 )
 Array ( [0] = 0 [1] = 0 [11] = 0 [12] = 0 [13] = 0 [14] = 0 [15]s
 = 30 [16] = 0 [17] = 0 [19] = 0 )
 
 The query only return 2 rows:
 
 15 | 30
 0 | 15547
 
 What am I doing wrong? Is there a more elegant way to achieve what I want?
 
 Thanks.
 
 -- 
 Paul Halliday
 Ideation | Individualization | Learner | Achiever | Analytical
 http://www.pintumbler.org
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

Paul-

Why not say:

$cat = array();
if(isset($row[1])
{
$cat[$row[1]] = $row[0];
}

print_r($cat);

Regards,

-Josh
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help.

2010-07-30 Thread Paul Halliday
On Fri, Jul 30, 2010 at 3:44 PM, Joshua Kehn josh.k...@gmail.com wrote:

 On Jul 30, 2010, at 2:36 PM, Paul Halliday wrote:

 I have a query that may not always return a result for a value, I need
 to reflect this with a 0. I am trying to overcome this by doing this
 (the keys are ID's):

 while ($row = mysql_fetch_row($statusQuery)) {

        $cat = 
 array(0=0,1=0,11=0,12=0,13=0,14=0,15=0,16=0,17=0,19=0);

        switch ($row[1]) {
            case 0: $cat[0] = $row[0]; break;
            case 1: $cat[1] = $row[0]; break;
            case 11: $cat[11] = $row[0]; break;
            case 12: $cat[12] = $row[0]; break;
            case 13: $cat[13] = $row[0]; break;
            case 14: $cat[14] = $row[0]; break;
            case 15: $cat[15] = $row[0]; break;
            case 16: $cat[16] = $row[0]; break;
            case 17: $cat[17] = $row[0]; break;
            case 19: $cat[19] = $row[0]; break;
        }

        print_r($cat);
    }

 Which gives me this:

 Array ( [0] = 15547 [1] = 0 [11] = 0 [12] = 0 [13] = 0 [14] = 0
 [15] = 0 [16] = 0 [17] = 0 [19] = 0 )
 Array ( [0] = 0 [1] = 0 [11] = 0 [12] = 0 [13] = 0 [14] = 0 [15]s
 = 30 [16] = 0 [17] = 0 [19] = 0 )

 The query only return 2 rows:

 15 | 30
 0 | 15547

 What am I doing wrong? Is there a more elegant way to achieve what I want?

 Thanks.

 --
 Paul Halliday
 Ideation | Individualization | Learner | Achiever | Analytical
 http://www.pintumbler.org

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 Paul-

 Why not say:

 $cat = array();
 if(isset($row[1])
 {
    $cat[$row[1]] = $row[0];
 }

 print_r($cat);

 Regards,

 -Josh

I need the results that don't have values assigned though.

ex:

c = 0
h = 9
t = 0
f = 21

Even if the query returned only:

h = 9
f = 21

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help.

2010-07-30 Thread Joshua Kehn

On Jul 30, 2010, at 3:03 PM, Paul Halliday wrote:

 
 Paul-
 
 Why are those values not defaulted to 0 in the database?
 
 Regards,
 
 -Josh
 
 
 
 They are defaulted, the query is grouping:
 
 select count(status) as count, status from table group by status order
 by status desc;

Paul-

Correct, so stuff with a status of 0 will still show up unless I'm missing 
something.

Regards,

-Josh
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2007-03-04 Thread Stut

Ryan A wrote:

I have a login/password file with these kind of  values:
user1:pass1
user2:pass2
cat:dog
love:hate

I have  opened the file and put it into an array with this code:
(thanks to richard lynch from this list for idea and code snippets)

$file =  file_get_contents('a.htpasswd');
preg_match_all('/(.*):(.*)$/msU', $file,  $htpassd);

but how do I get it into this format  :

$users['username'] = 'password'

without using a loop? I was  thinking something like array_flip or 
array_splice??
(The reason I dont want to use a loop (for,while) is there can be thousands of 
user:pass combos in the files and thousands of logins and attempted logins a 
day)


My advice would be to swap to using a database. With that number of 
users it's going to give you a huge boost in performance. SQLite would do.


If you *need* to stick to using the file, are you looking for a 
particular username or just want to load the whole list?


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2007-03-04 Thread Ryan A
Hey Stut,
Thanks for replying.

Will be making two versions, one with a DB and one to work with the file for 
the old school folks who dont want to convert their file and use new fangled 
databases... some people its easier to just not argue or try to convince...
and however stupid someone's opinion is, they are still entitled to it...esp 
when you are thinking of (maybe) selling a future product it does not make much 
sense telling them they are stupid :-))

If you *need* to stick to using the file, are you looking for a 
particular username or just want to load the whole list?

I'm looking to match a login (user:pass)... so I would need to load the whole 
list right? or do you have an alternative idea? am totally open to suggestions 
and alternatives at this point... just looking for the easiest way in terms of 
server load and processing..which is why I am trying to avoid a for() or 
while() loop.

Thanks!
Ryan

Stut [EMAIL PROTECTED] wrote: Ryan A wrote:
 I have a login/password file with these kind of  values:
 user1:pass1
 user2:pass2
 cat:dog
 love:hate
 
 I have  opened the file and put it into an array with this code:
 (thanks to richard lynch from this list for idea and code snippets)
 
 $file =  file_get_contents('a.htpasswd');
 preg_match_all('/(.*):(.*)$/msU', $file,  $htpassd);
 
 but how do I get it into this format  :
 
 $users['username'] = 'password'
 
 without using a loop? I was  thinking something like array_flip or 
 array_splice??
 (The reason I dont want to use a loop (for,while) is there can be thousands 
 of user:pass combos in the files and thousands of logins and attempted logins 
 a day)

My advice would be to swap to using a database. With that number of 
users it's going to give you a huge boost in performance. SQLite would do.

If you *need* to stick to using the file, are you looking for a 
particular username or just want to load the whole list?

-Stut



--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
 
-
Now that's room service! Choose from over 150,000 hotels 
in 45,000 destinations on Yahoo! Travel to find your fit.

Re: [PHP] Array help

2007-03-04 Thread Stut

Ryan A wrote:
Will be making two versions, one with a DB and one to work with the file 
for the old school folks who dont want to convert their file and use 
new fangled databases... some people its easier to just not argue or 
try to convince...
and however stupid someone's opinion is, they are still entitled to 
it...esp when you are thinking of (maybe) selling a future product it 
does not make much sense telling them they are stupid :-))


Fair enough.


If you *need* to stick to using the file, are you looking for a
particular username or just want to load the whole list?

I'm looking to match a login (user:pass)... so I would need to load the 
whole list right? or do you have an alternative idea? am totally open to 
suggestions and alternatives at this point... just looking for the 
easiest way in terms of server load and processing..which is why I am 
trying to avoid a for() or while() loop.


Loops are not evil, but I understand what you're saying. You basically 
have a few options. Firstly... is the file in alphabetical order? If yes 
then you can use a binary chop algorithm to seek around the file to find 
the right line. However, I doubt the file is organised alphabetically, so...


The second option would be to load the entire file into a variable and 
do a regex to find the password hash. I'm not great at regexes, but you 
want a multi-line regex looking for \n followed by the username, 
followed by a :. Should be pretty easy to knock that up. However, this 
is not great if the file is not trivial in size.


The third option is to use fgets to read each line in the file, check if 
it starts with username:, and if it does then you've found it. This 
would be the slowest option, but the most economical and I think you'd 
be surprised at how fast PHP can do this.


Another option would be to break the single file in to several files, 
maybe one for each first character. That way you would limit the number 
of entries you need to check.


Hope that helps.

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2007-03-04 Thread Tijnema !

Well, you are using the file_get_contents function right now, what about a
loop that reads the file line by line, checks if the user matches, and stops
when found the right user?

it's an all in one loop :)

just like this:
$found = false;
$fp = fopen($file,r);
while(!feof($fp)  $found == false)
{
$line = fread($fp,256);
if($line == $user.:.$pass)
{
$found = true;
}
}

It is possible to get it even smaller, but i'm not a genius in writing fast
code :P

Tijnema

On 3/4/07, Ryan A [EMAIL PROTECTED] wrote:


Hey Stut,
Thanks for replying.

Will be making two versions, one with a DB and one to work with the file
for the old school folks who dont want to convert their file and use new
fangled databases... some people its easier to just not argue or try to
convince...
and however stupid someone's opinion is, they are still entitled to
it...esp when you are thinking of (maybe) selling a future product it does
not make much sense telling them they are stupid :-))

If you *need* to stick to using the file, are you looking for a
particular username or just want to load the whole list?

I'm looking to match a login (user:pass)... so I would need to load the
whole list right? or do you have an alternative idea? am totally open to
suggestions and alternatives at this point... just looking for the easiest
way in terms of server load and processing..which is why I am trying to
avoid a for() or while() loop.

Thanks!
Ryan

Stut [EMAIL PROTECTED] wrote: Ryan A wrote:
 I have a login/password file with these kind of  values:
 user1:pass1
 user2:pass2
 cat:dog
 love:hate

 I have  opened the file and put it into an array with this code:
 (thanks to richard lynch from this list for idea and code snippets)

 $file =  file_get_contents('a.htpasswd');
 preg_match_all('/(.*):(.*)$/msU', $file,  $htpassd);

 but how do I get it into this format  :

 $users['username'] = 'password'

 without using a loop? I was  thinking something like array_flip or
array_splice??
 (The reason I dont want to use a loop (for,while) is there can be
thousands of user:pass combos in the files and thousands of logins and
attempted logins a day)

My advice would be to swap to using a database. With that number of
users it's going to give you a huge boost in performance. SQLite would do.

If you *need* to stick to using the file, are you looking for a
particular username or just want to load the whole list?

-Stut



--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

-
Now that's room service! Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.


Re: [PHP] Array help

2007-03-04 Thread Ryan A
Hey!

Thanks Stut, Tijnema.

I'll test out the ideas you guys contributed to me.. after I finish a working 
copy will ask you guys to give it a look over ;)

@Stut: The list is not in alphabetical order.. and 2, I have no idea of the 
size of the file (for the regex suggestion) but I am guessing it can be quite 
big with just 5k members. I like the FGETs idea you and Tijnema gave me... I 
think I'll go with that.

Am still working on a few other bits and pieces..

Cheers!
R


--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
 
-
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food  Drink QA.

Re: [PHP] array help

2005-07-14 Thread Robert Cummings
Did you bother to initialize $table as an array() or are you another
lazy slob of a programmer that expects the engine to read your mind
(cluttered as that may be)?

Cheers,
Rob.

On Thu, 2005-07-14 at 18:33, Fletcher Mattox wrote:
 How does one represent a MySQL table as a two dimensional array
 using the column names as one of the indices?  My naive attempt
 went something like this:
 
   while ($row = mysqli_fetch_assoc($result))
   $table[] = $row;
 
 but that generated this error;
 
   Fatal error: [] operator not supported for strings
 
 Ok.  So then I try to explicitly assign each row, like this:
 
   while ($row = mysqli_fetch_assoc($result))
   $table[$i++] = $row;
 
 While that generates no error, $table contains nothing useful when
 I'm done.  So then I try to assign each row and column, like this:
 
   while ($row = mysqli_fetch_assoc($result)) {
   foreach ( $row as $col = $val)
   $table[$i][$col] = $val;
   $i++;
   }
 
 And that got me this error:
 
   Fatal error: Cannot use string offset as an array 
 
 So clearly my understanding of PHP arrays is lacking.
 Please help.
 
 Thanks
 Fletcher
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array help

2005-07-14 Thread Richard Davey
Hello Fletcher,

Thursday, July 14, 2005, 11:33:36 PM, you wrote:

FM while ($row = mysqli_fetch_assoc($result))
FM $table[] = $row;

FM but that generated this error;

FM Fatal error: [] operator not supported for strings

The above WILL work providing that (1) $table hasn't been set
elsewhere in your script as a string, or (2) $table has been set as an
array ($table = array()) prior to being used.

Best regards,

Richard Davey
-- 
 http://www.launchcode.co.uk - PHP Development Services
 I do not fear computers. I fear the lack of them. - Isaac Asimov

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array help

2005-07-14 Thread Fletcher Mattox
Rob writes:

 Did you bother to initialize $table as an array() or are you another
 lazy slob of a programmer that expects the engine to read your mind
 (cluttered as that may be)?

Bingo.  

You seem to have no trouble reading my mind, why can't php? :)
Years of perl programming has promoted a certain sloth in my character.
It manifests in many different insidious forms.  Ask my wife.

Thanks!
Fletcher lazy slob Mattox

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array Help

2005-03-15 Thread Richard Lynch
 I'm running into the problem of not having a server that gives me database
 access or ability to use files to store my data ... Yeah, I know, it
 sucks.

If switching servers isn't an option, just pay for another one somewhere,
and then re-direct or something.

The time you save HAS to be worth more than the cost of cheap hosting with
real service/support.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array Help

2005-03-14 Thread Robert Cummings
On Mon, 2005-03-14 at 18:07, Phil Neeb wrote:
 Greets,
 I'm running into the problem of not having a server that gives me database 
 access or ability to use files to store my data ... Yeah, I know, it sucks. 
 Anyway ... My page has a number of profiles about people involved with my 
 organization and all the profiles load into a set appearance.  I have all 
 the information about each person stored in individual arrays (if there's an 
 easier way to do this w/o database or files, I'd love to hear it) ... 
 anyway, I pass a variable through the URL which causes the array info to 
 load, but I use an if statement for EVERYONE which makes my work way too 
 tedious ... The variable I pass is the same value as the name each person's 
 array (the variable is stored in the link) so, I'm curious if there's a way 
 I can use the variable as the array name and cut out those tons of if 
 statements. 

if( isset( $$person ) )
{
$profile = $$person;
}

Where the value of $person is a string that corresponds to the profile
array name you wish to access.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Array help

2004-11-02 Thread Jay Blanchard
[snip]
[2] = Array(
[0] = Array(
[0] = {textlinks 0_15}
[1] = {textlinks 16_30}
)

[1] = Array(
[0] = 0_15
[1] = 16_30
)
)


As you can see the third one (array [2] )for some reason is coming out
as a
double dimension array, is there any way to make it too into a single
dimension and have just one key/value like the first 2 arrays?
[/snip]

Yes.



Of course the question is, how are you builing this array? 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2004-07-23 Thread Matt M.
 I've got a field in my database that contains a single numerical character
 (1 or 2 or 3, etc.). I need to load a different background image in
 one cell of a table depending upon what the number the field contains.
 What's the easy syntax for associating entries in the field (1 or 2 or
 3, etc.) with image filenames (bkgrnd-default.gif or
 bkgrnd-positive.gif or bkgrnd-negative.gif, etc.)

 $images[1] = 'bkgrnd-default.gif';
 $images[2] = 'bkgrnd-positive.gif';
 $images[3] = 'bkgrnd-negative.gif';

do you query, get the result in a variable, I'll use $field

img src=?php echo $images[$field];? /

you could do some error checking to make sure the value in $field
exists in the $images array

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2004-07-23 Thread Jason Davidson
You can either hard code the associations, with something like a
swtich statement, or i suppose loop thru one array, adding a key value
pair of the numbers = background images.  Or, you could create a
table called Backgrounds, give them an id which you store in the
existing field of your db, and use a table join to query the
background name out .  Does this help any?

Jason

On Fri, 23 Jul 2004 16:02:06 -0500, Robb Kerr
[EMAIL PROTECTED] wrote:
 I've got a field in my database that contains a single numerical character
 (1 or 2 or 3, etc.). I need to load a different background image in
 one cell of a table depending upon what the number the field contains.
 What's the easy syntax for associating entries in the field (1 or 2 or
 3, etc.) with image filenames (bkgrnd-default.gif or
 bkgrnd-positive.gif or bkgrnd-negative.gif, etc.)
 
 Thanx,
 Robb
 
 --
 Robb Kerr
 Digital IGUANA
 Helping Digital Artists Achieve their Dreams
 
 http://www.digitaliguana.com
 http://www.cancerreallysucks.org
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2004-07-23 Thread Matthew Sims

 I've got a field in my database that contains a single numerical character
 (1 or 2 or 3, etc.). I need to load a different background image in
 one cell of a table depending upon what the number the field contains.
 What's the easy syntax for associating entries in the field (1 or 2 or
 3, etc.) with image filenames (bkgrnd-default.gif or
 bkgrnd-positive.gif or bkgrnd-negative.gif, etc.)

 Thanx,
 Robb


You mean like:

imgBkgrnd = array(1= bkgrnd-default.gif, 2 =
bkgrnd-positive.gif, 3 = bkgrnd-negative.gif);

http://us2.php.net/manual/en/function.array.php

-- 
--Matthew Sims
--http://killermookie.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2004-07-23 Thread Robb Kerr
On Fri, 23 Jul 2004 14:21:42 -0700 (PDT), Matthew Sims wrote:

 imgBkgrnd = array(1= bkgrnd-default.gif, 2 =
 bkgrnd-positive.gif, 3 = bkgrnd-negative.gif);

You got it...

imgBkgrnd = array(1= bkgrnd-default.gif, 2 = bkgrnd-positive.gif,
3 = bkgrnd-negative.gif);
imgNeeded = table['field'];
imgName = ???

Now, how do I get the image name associated with the key number obtained
from my table out of the array and into the variable so that I can use it
later in the HTML?

Thanx, Robb
-- 
Robb Kerr
Digital IGUANA

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Array help

2004-07-23 Thread Pablo Gosse
Robb Kerr wrote:
 On Fri, 23 Jul 2004 14:21:42 -0700 (PDT), Matthew Sims wrote:
 
 imgBkgrnd = array(1= bkgrnd-default.gif, 2 =
 bkgrnd-positive.gif, 3 = bkgrnd-negative.gif);
 
 You got it...
 
 imgBkgrnd = array(1= bkgrnd-default.gif, 2 =
 bkgrnd-positive.gif, 3 = bkgrnd-negative.gif); imgNeeded =
 table['field']; imgName = ???  
 
 Now, how do I get the image name associated with the key number
 obtained from my table out of the array and into the variable so that
 I can use it later in the HTML?  
 
 Thanx, Robb
 --
 Robb Kerr
 Digital IGUANA

$imgBkgrnd[i] where 'i' is the number returned from your DB.

HTH.

Pablo

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2004-07-23 Thread Matt M.
  imgBkgrnd = array(1= bkgrnd-default.gif, 2 =
  bkgrnd-positive.gif, 3 = bkgrnd-negative.gif);
 
 You got it...
 
 imgBkgrnd = array(1= bkgrnd-default.gif, 2 = bkgrnd-positive.gif,
 3 = bkgrnd-negative.gif);
 imgNeeded = table['field'];
 imgName = ???
 


http://us3.php.net/array

$imgBkgrnd = array(1= bkgrnd-default.gif, 2 =
bkgrnd-positive.gif, 3 = bkgrnd-negative.gif);
$imgNeeded = table['field'];
$imgName = $imgBkgrnd[$imgNeeded];

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2004-07-23 Thread Matthew Sims
  imgBkgrnd = array(1= bkgrnd-default.gif, 2 =
  bkgrnd-positive.gif, 3 = bkgrnd-negative.gif);

 You got it...

 imgBkgrnd = array(1= bkgrnd-default.gif, 2 =
 bkgrnd-positive.gif,
 3 = bkgrnd-negative.gif);
 imgNeeded = table['field'];
 imgName = ???



 http://us3.php.net/array

 $imgBkgrnd = array(1= bkgrnd-default.gif, 2 =
 bkgrnd-positive.gif, 3 = bkgrnd-negative.gif);
 $imgNeeded = table['field'];
 $imgName = $imgBkgrnd[$imgNeeded];


Yup, just like that.

You can even get away with just:

$imgBkgrnd = array(1=
bkgrnd-default.gif,bkgrnd-positive.gif,bkgrnd-negative.gif);

as PHP will automatically assign bkgrnd-positive.gif with 2 and
bkgrnd-negative.gif with 3.

And can even do this:

$imgName = $imgBkgrnd[$table['field']];

Though I admit it looks clunky.

-- 
--Matthew Sims
--http://killermookie.org


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2003-07-28 Thread skate
because in reality I don't have just these 4 fields
 but 43 fields in one table that have to be taken. Select *... seems a
much
 easier way to get it


you have 43 fields in 1 table? if you are seriously considering offering
hosting packages, then i'm guessing your wanting to be half professional
about it. you should look into restructuring you table. do you really NEED
to have all 43 fields in 1 table? i've made the same mistake myself, and
believe me, it's a lot easier if you simplify your tables. you might get a
little more complicated code, but it'll help you tremendously in the future.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array help

2003-07-27 Thread Jason Wong
On Monday 28 July 2003 10:19, Ryan A wrote:

 After asking for help on the list Skate gave me the following code as an
 example:
 **
 $n = 0;
 $result = mysql_query( SELECT id, title, text, date FROM news ORDER BY
 date DESC );
 while ($rows = mysql_fetch_array($result)) {
   if( $rows ==  ){  continue;  }
   extract( $rows );   ///extract our result into variables named after our
 fields
   $content[id][$n] = $id;
   $content[title][$n] = $title;
   $content[text][$n] = $text;
   $content[date][$n] = $date;
   $n++; //increment our number for next time...
  }
 **
 My question is: is there anyway I can use a select * from to do the
 same thing and then dump as usual to
 $content[id][$n] = $id; $content[title][$n] = $title; instead of a select
 id, title, text, date because in reality I don't have just these 4 fields
 but 43 fields in one table that have to be taken. Select *... seems a
 much easier way to get it

*** Untried and untested ***

  $query = SELECT * FROM table;
  $result = mysql_query($query) or die(Query failed);
  $n = 0;
  while ($line = mysql_fetch_assoc($result)) {
foreach ($line as $field = $value) {
  $data[$field][$n] = $value;
}
$n++;
  }
  print_r($data);

Season to taste.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
What one believes to be true either is true or becomes true.
-- John Lilly
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array help please

2003-01-05 Thread David T-G
John, et al --

...and then John Fishworld said...
% 
% can someone give me a bit of help / walthrough the following for me !

Let's see if I can help.


% this first bits is okay
% $mysql query1
% result
% array[cityid][cityname]
% 
% mysql query2
% result
% array[cityid][cityname]

Are CityIDs unique, like US-GA-ATL and CN-QC-MON or 214365 and 214387, or
is duplication possible?  If the IDs are unique then adding duplicates
won't cause duplicate entries.


% 
% now what i want to do is kick out any doubles in my array and resort them
% alphebetically by cityname ?!

Check out array_merge and array_multisort to put the two together and
sort on the second key, respectively.


% 
% 
% help !


HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!




msg91646/pgp0.pgp
Description: PGP signature


RE: [PHP] array help please

2003-01-05 Thread David Freeman

  $mysql query1
  result
  array[cityid][cityname]
 
  mysql query2
  result
  array[cityid][cityname]
 
  now what i want to do is kick out any doubles in my array
  and resort them alphebetically by cityname ?!

It's difficult to answer this question without knowing more about the
context and the way you have your database laid out.

In any event, sorting stuff and getting removing duplicates is probably
better achieved in your mysql query than in php.

Something like this would get you close (you'll have to figure it out
for your database as you didn't give much to go on)...

SELECT cityid, DISTINCE(cityname) FROM my_table WHERE some = 'condition'
ORDER BY cityname

Basically, use DISTINCT() to remove duplicates and use ORDER BY to set
the display order.

CYA, Dave




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Array Help

2001-11-27 Thread Jack Dempsey

you can just kept adding []'s

$var[category][subcategory][Item] = url;

-Original Message-
From: Brian V Bonini [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 27, 2001 4:56 PM
To: PHP Lists
Subject: [PHP] Array Help


How can I access the inner most info in this array?
Ie, Item and url

$var = array(
 category  = array(
  subcategory  = array(
Item = url
),
 )
);

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Array HELP PLEASE

2001-11-08 Thread René Fournier

Oops, guess I posted too soon.  Just figured out the problem myself (use a
do/while...).  Thanks anyways.

 -Original Message-
 From: René Fournier [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, November 08, 2001 3:25 PM
 To: Php-General
 Subject: [PHP] Array HELP PLEASE


 (Before you write RTFM, please know that I have checked www.php.net,
 zend.com, phpbuilder.com, et all, and--in the eternal words of
 Bono--I still
 haven't found what I'm looking.)

 The situation:  I extract an array from a MySQL table. Code:

   $models = mysql_fetch_array(mysql_query(SELECT * FROM models WHERE
 lang='$lang' AND key1='data' AND key2='$series',$db));

 Based on the above criteria, there should be two rows in $modelsrow, with
 each row containing about twenty elements.  (A two-dimensional array,
 right?)  All I want to do is display the contents of $models.   With the
 following...

   for ($i = 1; $i = 20; $i++) {
   echo $models[$i].p;
   }

 ...I get just one row.  How can I also display the other row?  I've tried
 variations of $models[1][2], but I just can't get right syntax.  (Help is
 much appreciated. Thanks.)

 If you know of a good tutorial on multidimension arrays + mySQL,
 that would
 be nice too.

 ...Rene


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Array HELP PLEASE

2001-11-08 Thread Jim Lucas

read this page a little closer!
http://www.php.net/manual/en/function.mysql-fetch-array.php

the mysql_fetch_array();  does not pull all the results in one big array.
it IS only a single row of data.

try this out, it should do what you are looking to do.

$results = mysql_query(SELECT * FROM models WHERE lang='$lang' AND
key1='data' AND key2='$series',$db);

while ($models = mysql_fetch_array($results))
{
echo $models .p;
}



Jim
- Original Message -
From: René Fournier [EMAIL PROTECTED]
To: Php-General [EMAIL PROTECTED]
Sent: Thursday, November 08, 2001 2:25 PM
Subject: [PHP] Array HELP PLEASE


 (Before you write RTFM, please know that I have checked www.php.net,
 zend.com, phpbuilder.com, et all, and--in the eternal words of Bono--I
still
 haven't found what I'm looking.)

 The situation:  I extract an array from a MySQL table. Code:

 $models = mysql_fetch_array(mysql_query(SELECT * FROM models WHERE
 lang='$lang' AND key1='data' AND key2='$series',$db));

 Based on the above criteria, there should be two rows in $modelsrow, with
 each row containing about twenty elements.  (A two-dimensional array,
 right?)  All I want to do is display the contents of $models.   With the
 following...

 for ($i = 1; $i = 20; $i++) {
 echo $models[$i].p;
 }

 ...I get just one row.  How can I also display the other row?  I've tried
 variations of $models[1][2], but I just can't get right syntax.  (Help is
 much appreciated. Thanks.)

 If you know of a good tutorial on multidimension arrays + mySQL, that
would
 be nice too.

 ...Rene


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Array HELP PLEASE

2001-11-08 Thread René Fournier

Or maybe not. :-) Although I got both rows displaying, they're actually two
long to fit comfortably (w/o horizontally scrolling).  So...  I'd like to
flip the axis of the table, so my header row runs vertically.  But with the
vagaries of html tables, I'm kinda stumped as to how to run the do/while+for
loop.  This is what I've got now (more or less):

fld1fld2fld3
big red house
little  bluedog
longyellow  string

With this code:
===
// MODELS A

echo table border=1 cellpadding=2 cellspacing=0;
echo tr;
for ($i = 6; $i = 25; $i++) {
echo td valign=top align=left
class=deemph.stripslashes($modelsheader[$i])./td;
}
echo /tr;

do {
echo tr;
for ($i = 6; $i = 25; $i++) {
echo td valign=top align=left
class=normal.stripslashes($models[$i])./td;
}
echo /tr;

} while ($models = mysql_fetch_array($result));
echo /table;
=
This is what I WOULD LIKE to have:

fld1big little  long
fld2red blueyellow
fld3house   dog string
==

I can't figure how I would display element 1 of $modelsheader and every
first element of $models, then increment and loop...  That is, I would like
to be able to refer to $models such that $models[0][0] referred to the first
element of the first row and, say, $models[1][0] referred to the first
element of the second row, and so on.



 -Original Message-
 From: René Fournier [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, November 08, 2001 3:39 PM
 To: Php-General
 Subject: RE: [PHP] Array HELP PLEASE


 Oops, guess I posted too soon.  Just figured out the problem myself (use a
 do/while...).  Thanks anyways.

  -Original Message-
  From: René Fournier [mailto:[EMAIL PROTECTED]]
  Sent: Thursday, November 08, 2001 3:25 PM
  To: Php-General
  Subject: [PHP] Array HELP PLEASE
 
 
  (Before you write RTFM, please know that I have checked www.php.net,
  zend.com, phpbuilder.com, et all, and--in the eternal words of
  Bono--I still
  haven't found what I'm looking.)
 
  The situation:  I extract an array from a MySQL table. Code:
 
  $models = mysql_fetch_array(mysql_query(SELECT * FROM models WHERE
  lang='$lang' AND key1='data' AND key2='$series',$db));
 
  Based on the above criteria, there should be two rows in
 $modelsrow, with
  each row containing about twenty elements.  (A two-dimensional array,
  right?)  All I want to do is display the contents of $models.   With the
  following...
 
  for ($i = 1; $i = 20; $i++) {
  echo $models[$i].p;
  }
 
  ...I get just one row.  How can I also display the other row?
 I've tried
  variations of $models[1][2], but I just can't get right syntax.
  (Help is
  much appreciated. Thanks.)
 
  If you know of a good tutorial on multidimension arrays + mySQL,
  that would
  be nice too.
 
  ...Rene
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Array HELP PLEASE

2001-11-08 Thread Martin Towell

try changing these lines:

echo tr;
for ($i = 6; $i = 25; $i++) {
echo td valign=top align=left
class=normal.stripslashes($models[$i])./td;
}
echo /tr;

to:

echo trtd valign=top align=left class=normal;
for ($i = 6; $i = 25; $i++) {
echo
stripslashes($models[$i]).br;
}
echo /td/tr;

Martin T

-Original Message-
From: René Fournier [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 09, 2001 10:06 AM
To: Php-General
Subject: RE: [PHP] Array HELP PLEASE


Or maybe not. :-) Although I got both rows displaying, they're actually two
long to fit comfortably (w/o horizontally scrolling).  So...  I'd like to
flip the axis of the table, so my header row runs vertically.  But with the
vagaries of html tables, I'm kinda stumped as to how to run the do/while+for
loop.  This is what I've got now (more or less):

fld1fld2fld3
big red house
little  bluedog
longyellow  string

With this code:
===
// MODELS A

echo table border=1 cellpadding=2 cellspacing=0;
echo tr;
for ($i = 6; $i = 25; $i++) {
echo td valign=top align=left
class=deemph.stripslashes($modelsheader[$i])./td;
}
echo /tr;

do {
echo tr;
for ($i = 6; $i = 25; $i++) {
echo td valign=top align=left
class=normal.stripslashes($models[$i])./td;
}
echo /tr;

} while ($models = mysql_fetch_array($result));
echo /table;
=
This is what I WOULD LIKE to have:

fld1big little  long
fld2red blueyellow
fld3house   dog string
==

I can't figure how I would display element 1 of $modelsheader and every
first element of $models, then increment and loop...  That is, I would like
to be able to refer to $models such that $models[0][0] referred to the first
element of the first row and, say, $models[1][0] referred to the first
element of the second row, and so on.



 -Original Message-
 From: René Fournier [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, November 08, 2001 3:39 PM
 To: Php-General
 Subject: RE: [PHP] Array HELP PLEASE


 Oops, guess I posted too soon.  Just figured out the problem myself (use a
 do/while...).  Thanks anyways.

  -Original Message-
  From: René Fournier [mailto:[EMAIL PROTECTED]]
  Sent: Thursday, November 08, 2001 3:25 PM
  To: Php-General
  Subject: [PHP] Array HELP PLEASE
 
 
  (Before you write RTFM, please know that I have checked www.php.net,
  zend.com, phpbuilder.com, et all, and--in the eternal words of
  Bono--I still
  haven't found what I'm looking.)
 
  The situation:  I extract an array from a MySQL table. Code:
 
  $models = mysql_fetch_array(mysql_query(SELECT * FROM models WHERE
  lang='$lang' AND key1='data' AND key2='$series',$db));
 
  Based on the above criteria, there should be two rows in
 $modelsrow, with
  each row containing about twenty elements.  (A two-dimensional array,
  right?)  All I want to do is display the contents of $models.   With the
  following...
 
  for ($i = 1; $i = 20; $i++) {
  echo $models[$i].p;
  }
 
  ...I get just one row.  How can I also display the other row?
 I've tried
  variations of $models[1][2], but I just can't get right syntax.
  (Help is
  much appreciated. Thanks.)
 
  If you know of a good tutorial on multidimension arrays + mySQL,
  that would
  be nice too.
 
  ...Rene
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



Re: [PHP] Array help please

2001-05-04 Thread Jason Stechschulte

On Fri, May 04, 2001 at 01:19:57PM +0100, peter.beal wrote:
 I'm trying to debug some software that I downloaded from the web.
 It seems to work fine most of the time however it occasionally crashed with
 database errors.
 When I look at the code it has a lot of array references that i don't
 understand
 e.g. $Session[clientID]
 most references at are of the form $arrayname[item]  or $arrayname[$item]
 as I would expect.
 is the example correct code? if so what does it mean?

It either does the same thing as $Sessin[clientID] The quotes are
optional but recommended, because clientID could be defined as a
constant and that could give unexpected results.

-- 
Jason Stechschulte
[EMAIL PROTECTED]
--
: How would you disambiguate these situations?

By shooting the person who did the latter.
 -- Larry Wall in [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Array help please

2001-05-04 Thread peter.beal

Thanks

Peter

Jason Stechschulte [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 On Fri, May 04, 2001 at 01:19:57PM +0100, peter.beal wrote:
  I'm trying to debug some software that I downloaded from the web.
  It seems to work fine most of the time however it occasionally crashed
with
  database errors.
  When I look at the code it has a lot of array references that i don't
  understand
  e.g. $Session[clientID]
  most references at are of the form $arrayname[item]  or
$arrayname[$item]
  as I would expect.
  is the example correct code? if so what does it mean?

 It either does the same thing as $Sessin[clientID] The quotes are
 optional but recommended, because clientID could be defined as a
 constant and that could give unexpected results.

 --
 Jason Stechschulte
 [EMAIL PROTECTED]
 --
 : How would you disambiguate these situations?

 By shooting the person who did the latter.
  -- Larry Wall in [EMAIL PROTECTED]

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Array help

2001-03-14 Thread David Robley

On Thu, 15 Mar 2001 10:56, Chris wrote:

  Hi,
 Is there a way to do an array_pop  with php3?

Off the top of my head:

use count to get the number of elements in the array
grab element(count - 1) as the popped value

Then (maybe)
unset(element[count-1])

may work; if not you might have to play around with assigning all the 
elements bar the last of your original array to a new array.

-- 
Please don't hit Reply to respond - use this address instead:
[EMAIL PROTECTED]
Local SMTP server is creatively munging domains!!! 

David Robley| WEBMASTER  Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet| http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Array help

2001-03-14 Thread James Atkinson

   Hi,
  Is there a way to do an array_pop  with php3?

Here's some PHP 3 compatable code that works the same as array_pop:

function _array_pop($stack) {
   $arrSize = count($stack);
   $x = 1;
   while(list($key, $val) = each($stack)) {
  if($x  count($stack)) {
 $tmpArr[] = $val;
  }
  else {
 $return_val = $val;
  }
  $x++;
   }
   $stack = $tmpArr;
   return($return_val);
}

Enjoy :)

- James


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Array help

2001-03-14 Thread Don Read


On 15-Mar-01 Chris wrote:
 Hi,
 Is there a way to do an array_pop  with php3?
 
 

unset($dirs[sizeof($dirs)-1]);  // php4 array_pop();

Regards,
-- 
Don Read [EMAIL PROTECTED]
-- If you are going to sin, sin against God, not the bureaucracy. 
  God will forgive you but the bureaucrats won't. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Array Help

2001-02-23 Thread php3

Addressed to: [EMAIL PROTECTED]
  [EMAIL PROTECTED]

** Reply to note from [EMAIL PROTECTED] Fri, 23 Feb 2001 12:20:12 -0500

 I've tried and tried and tried ;-)

 I have this array;

 $bikes = array(
   "Road"  = array(
  "Trek"  = array(
 "Trek 5200" = "road.php?brand=t5200"
 ),
  "Schwinn" = array(
 "Schwinn Fastback Pro" = "road.php?brand=schfp"
 ),
  "Moots" = array(
 "VaMoots"  = "road.php?brand=vamoots"
 ),
  "Lemond" = array(
 "Zurich" = "road.php?brand=zurich",
 "Chambery" = "road.php?brand=chambery",
 "BuenosAries" = "road.php?brand=bueno",
 "Tourmalet" = "road.php?brand=tourmalet"
  )
  ),
   "Dirt"  = array(
)
 );


I would probably do something like:

# reset( $Bikes )
while( list( $BikeType, $Manufacturers ) = each( $bikes )) {
   echo "$BikeTypeBR\n";


#   reset( $Manufacturers );
   while( list( $Mfr, $Models ) = each( $Manufacturers )) {
  echo "nbsp;nbsp;$MfrBR\n";

#  reset( $Models );
  while( list( $Model, $URL ) = each( $Models )) {
 echo "nbsp;nbsp;nbsp;nbsp;" .
   "A href=\"$URL\"$Model/ABR\n";  }
  }
   }


This would give

Road
  Trek
Trek  -- is a link
  Schwinn
Schwinn Fastback Pro  -- is a link
  Moots
VaMoots  --  is a link
  Lemond
Zurich  --  is a link
Chambery  --  is a link
BuenosAries  -- is a link
Tourmalet  -- is a link
Dirt


If you realy want

  Trek
  Schwinn
  Moots
  Lemond
Trek  -- is a link
Schwinn Fastback Pro  -- is a link
VaMoots  --  is a link
Zurich  --  is a link
Chambery  --  is a link
BuenosAries  -- is a link
Tourmalet  -- is a link

You need to do the outer look twice, doing a reset() in it between them,
and doing the reset()s I have commented out in the example.  Be aware if
you go thru the array more than once in the program it will be needed.




Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Array help needed

2001-01-18 Thread php3

Addressed to: CDitty [EMAIL PROTECTED]
  [EMAIL PROTECTED]

** Reply to note from CDitty [EMAIL PROTECTED] Thu, 18 Jan 2001 06:58:22 -0600

I see someone else has another suggestion that might be better, using
array_count().  You learn something new every day, which is why I watch
this list...


anyway, the thing I see in your code:


 while(list($index, $value) = each($dice)){ // Changed from $Input to
  ^

$Output[$Value]++; }
  ^

$Value != $value



I know my use of caps or not in this example sucks.  I usually always
use Caps On Each Word for my var names, but I am trying to switch to
what appears to be the php standard, lower case everywhere.  Sorry
about that...




Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Array help needed

2001-01-18 Thread April

As a generalness, from what I've seen, people who just switched from ASP use
somethingUppercase at first.  Then forget to capitalize it a few times, and
switch to completely lowercase in disgust (case-sensitivity can be quite a
shock when you're not used to it).  And the people who've done PHP since
they started out use whatever they damn well feel like using.  I use
Something_Something if left ot my own devices, I have no idea why, it just
happens.


- Original Message -
From: "Kristi Russell" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, January 18, 2001 10:40 AM
Subject: Re: [PHP] Array help needed


 I wouldn't call it a php standard.

 I personally feel that readability is far more important than following
 anything that 'appears' to be standard.  I use a format such as this for
 everything I name:  If one word, lowercase, if more than one word:
 $userSelectedDate or displayCalendar().  So basically everything starts
with
 a lowercase word and all words after that are capitalized at the
beginning.

 Just my two cents.
 Kristi


 - Original Message -
  I know my use of caps or not in this example sucks.  I usually always
  use Caps On Each Word for my var names, but I am trying to switch to
  what appears to be the php standard, lower case everywhere.  Sorry
  about that...
 
 
 
 
  Rick Widmer
  Internet Marketing Specialists
  http://www.developersdesk.com
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Array help needed

2001-01-18 Thread CDitty

Thanks.  Didn't see that myself.

Thanks for the help

Chris

At 10:28 AM 1/18/01, [EMAIL PROTECTED] wrote:
Addressed to: CDitty [EMAIL PROTECTED]
   [EMAIL PROTECTED]

** Reply to note from CDitty [EMAIL PROTECTED] Thu, 18 Jan 2001 
06:58:22 -0600

I see someone else has another suggestion that might be better, using
array_count().  You learn something new every day, which is why I watch
this list...


anyway, the thing I see in your code:

 
  while(list($index, $value) = each($dice)){ // Changed from $Input to
   ^

 $Output[$Value]++; }
   ^

$Value != $value



I know my use of caps or not in this example sucks.  I usually always
use Caps On Each Word for my var names, but I am trying to switch to
what appears to be the php standard, lower case everywhere.  Sorry
about that...




Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]