Re: [PHP] Newbie question to everybody....PHP

2002-05-11 Thread Olexandr Vynnychenko

Hello r,

Sunday, May 12, 2002, 4:25:37 AM, you wrote:

r> Greetings people,
r> Special greetings to all of you who have helped me in the past.

r> As most of you know i am a newbie, I learned a bit of PHP via webmonkey and
r> a few other places, seeing the power of PHP i decided to convert from Java
r> servlets and JSP (JSP coz its expensive to host and not many hosting
r> opportunities) so I baught a book called "The PHP black book".
r> Anyway, now that the background is done heres my questions:

r> 1)How many of you have seriously dug into arrays and has it been important
r> in your programming?
r> 1.1)Do you think you could have done the same thing you did with arrays
r> WITHOUT arrays?
r> (The reason i ask this is theres a whole chapter dedicated to arrays in the
r> book & its pretty frustrating)

Arrays in PHP are very useful and easy to use. I had no problem. And I
have no book about PHP :). I use manual, because it's the best book. I
looked through some books and find that the PHP manual is MUCH better.

r> Last question:
r> Is ther any function to make the program "sleep" for 10 seconds or so? or
r> does anybody have a function that does this?

It's called sleep() :)
Once again, use manual. Espacially if you work on Windows. Then just
download the manual in CHM.It includes index and search capabilities.

-- 
Best regards,
 Olexandrmailto:[EMAIL PROTECTED]


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




RE: [PHP] Newbie question to everybody....PHP

2002-05-11 Thread John Holmes

> 1)How many of you have seriously dug into arrays and has it been
important
> in your programming?
> 1.1)Do you think you could have done the same thing you did with
arrays
> WITHOUT arrays?
> (The reason i ask this is theres a whole chapter dedicated to arrays
in
> the
> book & its pretty frustrating)
> Last question:
> Is ther any function to make the program "sleep" for 10 seconds or so?
or
> does anybody have a function that does this?

You should be ashamed of yourself... www.php.net/sleep :)

As for arrays, they are invaluable and not that hard to understand.
Don't skip over them, read the chapter a couple times if you have to...

---John Holmes...


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




Re: [PHP] Newbie question to everybody....PHP

2002-05-11 Thread Rasmus Lerdorf

I have never really understood why people have problems with arrays.  Just
think of an array as a table of values.  A one-dimensional array would be
a table with a single column and each row has a number (or index)
assigned to it:

  +---++
  | 0 | Apple  |
  +---++
  | 1 | Orange |
  +---++
  | 2 | Banana |
  +---++

In PHP this simple array could br created like this:

  $fruits[0] = 'Apple';
  $fruits[1] = 'Orange';
  $fruits[2] = 'Banana';

Or there is a shortcut:

  $fruits = array('Apple','Orange','Banana');

Now, the row numbers (or indices) do not have to start at 0.

  $fruits[7] = 'Apple';
  $fruits[10] = 'Orange';
  $fruits['foo'] = 'Banana';

Would create a table like this:

  +-++
  | 7   | Apple  |
  +-++
  | 10  | Orange |
  +-++
  | foo | Banana |
  +-++

As you can see, row names don't even have to be numbers.  When using
non-numerical array indices like this the array is sometimes referred to
as an associative array, although in PHP we don't really differentiate.

The shortcut for creating this array where you name each row would be:

  $fruits = array(7=>'Apple', 10=>'Orange', 'foo'=>'Banana');

and obviously, to display an element you would do:

  echo $fruits['foo'];

To loop through and display every value in the array you can use foreach:

  foreach($fruits as $value) echo $value;

If you also want to display the row name (also known as the index or the
key):

  foreach($fruits as $key=>$value) echo "$key: $value";

Now, what really seems to confuse people are multi-dimensional arrays, but
they are exactly the same.  A multi-dimensional array can be thought of as
a table with more columns and you give each column a name as well now.
Just like a tic-tac-toe board:

  01
  +---++---+
  | 0 | Apple  | 1.99  |
  +---++---+
  | 1 | Orange | 2.99  |
  +---++---+
  | 2 | Banana | 0.89  |
  +---++---+

So the Apple element would be in position 0,0, Orange would be 1,0 and
0.89 would be in position 2,1.  Or in PHP you would write this as:

  $fruits[0][0] = 'Apple';
  $fruits[0][1] = 1.99;
  $fruits[1][0] = 'Orange';
  $fruits[1][1] = 2.99;
  $fruits[2][0] = 'Banana';
  $fruits[2][1] = 0.89;

That's of course a bit wordy.  If you think of this slightly differently,
consider that each row is actually a small array of two items.  The fruit
and the price.  So you could also write this as:

  $fruits[0] = array('Apple',1.99);
  $fruits[1] = array('Orange',2.99);
  $fruits[2] = array('Banana',0.89);

And then further breaking it down, we see that $fruits is just an array of
arrays, so it could actually be written as:

  $fruits = array(array('Apple',1.99), array('Orange',2.99), array('Banana',0.89));

and again, you don't have to use simple numbers to name your rows and
columns.

 NamePrice
  +---++---+
  | a | Apple  | 1.99  |
  +---++---+
  | b | Orange | 2.99  |
  +---++---+
  | c | Banana | 0.89  |
  +---++---+

  $fruits = array( 'a'=>array('Name'=>'Apple', 'Price'=>1.99),
   'b'=>array('Name'=>'Orange','Price'=>2.99),
   'c'=>array('Name'=>'Banana','Price'=>0.89) );

Looping through a multi-dimensional array is a little trickier:

 foreach($fruits as $k=>$arr) {
echo "$k: ";
foreach($arr as $kk=>$val) {
   echo "$kk: $val ";
}
echo "\n";
 }

If you run that code on the $fruits array you will get this output:

a: Name: Apple Price: 1.99
b: Name: Orange Price: 2.99
c: Name: Banana Price: 0.89

So basically you loop through all the rows and then inside each row
iteration you loop through each column.

This is about as complex as you are ever likely to get.  You may end up
with 3-dimensional or higher arrays, but there really is no difference.
The display loop will of course get more complex as you will need another
level of looping.  For a 3-dimensional array you would have items like
$fruits[0][0][0] and your display loop would be:

  foreach() {
foreach() {
  foreach() { }
}
  }

-Rasmus

 On Sat, 11 May 2002, r wrote:

> Greetings people,
> Special greetings to all of you who have helped me in the past.
>
> As most of you know i am a newbie, I learned a bit of PHP via webmonkey and
> a few other places, seeing the power of PHP i decided to convert from Java
> servlets and JSP (JSP coz its expensive to host and not many hosting
> opportunities) so I baught a book called "The PHP black book".
> Anyway, now that the background is done heres my questions:
>
> 1)How many of you have seriously dug into arrays and has it been important
> in your programming?
> 1.1)Do you think you could have done the same thing you did with arrays
> WITHOUT arrays?
> (The reason i ask this is theres a whole chapter dedicated to arrays in the
> book & its pretty frustrating)
> Last question:
> Is ther any function to make the program "sleep" for 10 sec

RE: [PHP] Newbie question to everybody....PHP

2002-05-11 Thread Matthew Walker

1. I have dug deeper into arrays than I care to remember.

2. Absolutely not.

3. See http://www.php.net/sleep and http://www.php.net/usleep

Glad to hear you're converting to PHP! It's an amazing language, and I
don't see it going away any time in the near future. Hope you have fun,
and be sure to ask if you have any more questions. I always try and
answer questions on the list if I have the time, and know the answer.

Matthew Walker
Senior Software Engineer
ePliant Marketing
 

-Original Message-
From: r [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, May 11, 2002 7:26 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Newbie question to everybodyPHP

Greetings people,
Special greetings to all of you who have helped me in the past.

As most of you know i am a newbie, I learned a bit of PHP via webmonkey
and
a few other places, seeing the power of PHP i decided to convert from
Java
servlets and JSP (JSP coz its expensive to host and not many hosting
opportunities) so I baught a book called "The PHP black book".
Anyway, now that the background is done heres my questions:

1)How many of you have seriously dug into arrays and has it been
important
in your programming?
1.1)Do you think you could have done the same thing you did with arrays
WITHOUT arrays?
(The reason i ask this is theres a whole chapter dedicated to arrays in
the
book & its pretty frustrating)
Last question:
Is ther any function to make the program "sleep" for 10 seconds or so?
or
does anybody have a function that does this?

ANY replies good,bad,flames will be welcome.
Cheers,
-Ryan.

/* You cannot get to the top by sitting on your bottom. */





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



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002
 

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




Re: [PHP] Newbie question to everybody....PHP

2002-05-11 Thread Bogdan Stancescu

Hi!

1. I believe every serious programmer out there uses arrays on a regular 
basis...
1.1. ...exactly because there are so many problems virtually unsolvable 
without them. Take for instance the case of a product page where people 
would fill in ordering quantitites.

My recommendation would be not to study arrays, but rather try solving 
problems using them - that way you'll have a better chance to remember 
what you've learned. But then again, that's me - maybe you learn better 
in other ways.

If you want to sleep, you can use sleep($seconds). But why in God's name 
would you want to do that?

Bogdan

r wrote:

>Greetings people,
>Special greetings to all of you who have helped me in the past.
>
>As most of you know i am a newbie, I learned a bit of PHP via webmonkey and
>a few other places, seeing the power of PHP i decided to convert from Java
>servlets and JSP (JSP coz its expensive to host and not many hosting
>opportunities) so I baught a book called "The PHP black book".
>Anyway, now that the background is done heres my questions:
>
>1)How many of you have seriously dug into arrays and has it been important
>in your programming?
>1.1)Do you think you could have done the same thing you did with arrays
>WITHOUT arrays?
>(The reason i ask this is theres a whole chapter dedicated to arrays in the
>book & its pretty frustrating)
>Last question:
>Is ther any function to make the program "sleep" for 10 seconds or so? or
>does anybody have a function that does this?
>
>ANY replies good,bad,flames will be welcome.
>Cheers,
>-Ryan.
>
>/* You cannot get to the top by sitting on your bottom. */
>
>
>
>
>




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




Re: [PHP] Newbie question to everybody....PHP

2002-05-11 Thread Neil Highley

Why would you want a scripting language to sleep, there is no such thing as
a loop in a web page (yes, I know it would be possible, but it would lock up
a users machine).

I know you can set up the apache daemon to run on-demand to conserver
resources, but I think you are getting mixed up between compiled and
interpreted (aka scripting) languages.

[EMAIL PROTECTED]
---
"Life must be lived as play."
- Plato (427 - 347 BC)

- Original Message -
From: "r" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, May 12, 2002 2:25 AM
Subject: [PHP] Newbie question to everybodyPHP


> Greetings people,
> Special greetings to all of you who have helped me in the past.
>
> As most of you know i am a newbie, I learned a bit of PHP via webmonkey
and
> a few other places, seeing the power of PHP i decided to convert from Java
> servlets and JSP (JSP coz its expensive to host and not many hosting
> opportunities) so I baught a book called "The PHP black book".
> Anyway, now that the background is done heres my questions:
>
> 1)How many of you have seriously dug into arrays and has it been important
> in your programming?
> 1.1)Do you think you could have done the same thing you did with arrays
> WITHOUT arrays?
> (The reason i ask this is theres a whole chapter dedicated to arrays in
the
> book & its pretty frustrating)
> Last question:
> Is ther any function to make the program "sleep" for 10 seconds or so? or
> does anybody have a function that does this?
>
> ANY replies good,bad,flames will be welcome.
> Cheers,
> -Ryan.
>
> /* You cannot get to the top by sitting on your bottom. */
>
>
>
>
>
> --
> 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