Any Ideas For Any Simple Php Codes? :)

Put Any Php Codes Here If You Wish Thank-you JamieHxD :slight_smile: :wink:

Hi Jamie.

What code are you looking for? I wonder if some links to basic, or getting started, tutorials would be better for you.

I’ll have a look around for some, but maybe other members know of some?

Anthony.

There’s Michael Morris’ 'PHP Basics’ thread here at SitePoint, you should read that. It points to the [URL=ā€œhttp://www.php.net/manual/en/index.phpā€]PHP Manual a lot too, however the guide at the manual isn’t too good IMO.

Ok Thank-you I’ve Looked At It And I Don’t Get Any Of It :s

Is there a part of the language you want to learn first? Strings, Arrays …

array’s Please. :slight_smile:

Sure. :wink:

Make sure you (try to) read the manual section on arrays too, but here you go.


<?php
/*
  Declare an array
*/
$array = array();

/*
  Add some elements
*/
$array[] = 'jamie';
$array[] = 'anthony';
$array[] = 'sitepoint';

/*
  Array indicies start at 0. So,
  jamie is at 0, anthony is at 1
  and sitepoint is at 3.
*/

/*
  display the item at index 1
*/
echo $array[1], PHP_EOL; #anthony

/*
  display the item at index 0
*/
echo $array[0], PHP_EOL; #jamie

/*
  You can also display them all
  using a loop, or 'foreach'.
*/
foreach($array as $name){
  echo $name, PHP_EOL;
}

Here’s another variation.


<?php
/*
  Declare an array
*/
$users = array();

/*
  Add some elements
*/
$users['jamie'] = 13;
$users['anthony'] = 31;

foreach($users as $name => $age){
  echo $name, ' is ', $age, PHP_EOL;
}

/*
  jamie is 13
  anthony is 31
*/

Ahh Ok Thank-You I Think I’ve Got The Jist Now. :slight_smile:

I’ve Eited You’re Code As It Came Up With Anthony Jamie Jamie Anthony Sitepoint so i took out the echo to sort it out. :slight_smile: Here this one.

<?php
$array = array();
$array[] = 'jamie';
$array[] = 'anthony';
$array[] = 'sitepoint';

foreach($array as $name){
  echo $name, PHP_EOL;
}

That looks good.

How do you think you can reverse the array so that the output is sitepoint, anthony, jamie without altering $array.

like this

<?php
$array = array();
$array[] = 'sitepoint';
$array[] = 'anthony';
$array[] = 'jamie';

foreach($array as $name){
  echo $name, PHP_EOL;
}


Nope, you’ve altered $array. :wink:



<?php
$array = array();
$array[] = 'jamie';
$array[] = 'anthony';
$array[] = 'sitepoint';

/* you can change anything below here */

Take a look at this list of array functions and read the description, are there any there that sound like they maybe useful? :wink:

absolutely no idea. :?

Try this…

PHP: array_reverse - Manual

I Can Not Do It. :frowning:

Ahhh Ha I’ve Found It. Here

 <?php

$array = array();
$array[] = 'jamie';
$array[] = 'anthony';
$array[] = 'sitepoint';

$trans = array("jamie" => 3, "anthony" => 2, "sitepoint" => 1);
$trans = array_flip($trans);
print_r($trans); 

Not quite. :stuck_out_tongue:

You were on the right track though!

<?php
$array = array();
$array[] = 'jamie';
$array[] = 'anthony';
$array[] = 'sitepoint';

/* you can change anything below here */

foreach(array_reverse($array) as $name){
  echo $name, PHP_EOL;
}

oh ok thank-you. :slight_smile: