Jump to content

[SOLVED] easy one! $variable[]= 'hello'; or $variable='hello';


farkewie

Recommended Posts

hello,

 

before you say it i do have the php manual here but not sure where to start looking. :-)

 

what is the difference between

 

$var[]='hello';

 

and..

 

$var='hello';

 

 

can someone give me a brief rundown? i am trying to create my own web album fron scratch im looking at sample code but dont just want to copy and paste i want to learn what its doing.

Link to comment
Share on other sites

$var[]='hello';

Adds the value to an numerically indexed array

You could do this to create an array holding multiple values.

$var[] = 'hello';
$var[]='goobye';
$var[]='cruel world';
echo $var[0].' '.$var[1].' '.$var[2];
//outputs goodbye cruel world

$var='hello';

Creates a variable that holds a single value;

Link to comment
Share on other sites

ok so

 

$var[] = 'hello';

$var[]='goobye';

$var[]='cruel world';

echo $var[0].' '.$var[1].' '.$var[2];

 

using this you have to remember how many times to define a new value because to use it you have echo them individually?

 

 echo $var[0].' '.$var[1].' '.$var[2];

Link to comment
Share on other sites

ok so

 

$var[] = 'hello';

$var[]='goobye';

$var[]='cruel world';

echo $var[0].' '.$var[1].' '.$var[2];

 

using this you have to remember how many times to define a new value because to use it you have echo them individually?

 

 echo $var[0].' '.$var[1].' '.$var[2];

 

You could assign your own index

<?php
//numeric indexes
$var[0]  = 'George';
$var[1] = 'Washinton';

//associative indexes
$var['fisrtname'] = 'George';
$var['lastname'] = 'Washington';

?>

Link to comment
Share on other sites

Thanks guys that should get me started.

 

 

now to workout the thumb creation...

 

i must admit i havea perfectly good script that i downloaded. but it has all the extra features i dont want and much more code that is needed. so it will be interesting how mine turns out..lol

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.