Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

class variable erro

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

class variable erro

Postby hasan4it » Sun Feb 13, 2011 5:15 am

please let me know what is the error in the following code

Code: Select all
<?php

class cars{
   
public $cars=array("Saab","Volvo","BMW","Toyota");
}
for($i=0; $i<4;$i++)
echo $cars[$i];
?>
hasan4it
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sun Feb 13, 2011 5:08 am

Re: class variable erro

Postby Kairu » Tue Apr 05, 2011 8:55 am

Code: Select all
<?php

class cars {
   public $cars = array("Saab","Volvo","BMW","Toyota");
   public function array_cars(){
      return $this->cars;
   }
}
$cars = new cars;
$cars_array = $cars->array_cars();
for($i=0; $i<4;$i++)
echo $cars_array[$i];
?>


See if you can wrap your head around that. ;)
Kairu
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Apr 05, 2011 7:48 am

Re: class variable erro

Postby VARUN006 » Fri Jul 22, 2011 10:38 am

what troubled me this time around is cookies......i understood its meaning n what does it do.....
but this line:
if(isset($msg)
is making me confused....as far as i knw the isset function is used to check wether the form is submitted or not...now then y is ($msg) is in parenthesis...wat does this line actually mean??will it check wether $msg value is submitted or not,or what will it do???i have not given any button or submit values $msg in the below code....kindly tell me what does this line actually does...


<?php
if(isset($_POST['submitted'])){
setcookie('font_size',$_POST['font_size']);
setcookie('font_color',$_POST['font_color']);
$msg = '<p>Your settings have been entered...click <a href="view.php">HERE</a>to
see them in action.</p>';
}
?>
<html>
<head>
<title>
CUSTOMIZE YOUR SETTINGS
</title>
</head>
<body>
<?php
if(isset($msg)){
print $msg;
}
?>

pls help.....
VARUN006
New php-forum User
New php-forum User
 
Posts: 21
Joined: Tue Jul 12, 2011 3:51 am

Re: class variable erro

Postby kasuals » Tue Aug 16, 2011 8:59 am

Old thread, but I'm bored so:

isset — Determine if a variable is set and is not NULL

http://www.php.net/manual/en/function.isset.php

All it is doing is making sure that $msg is not empty, and if it's not empty that print $msg.
kasuals
New php-forum User
New php-forum User
 
Posts: 16
Joined: Wed Aug 10, 2011 10:48 pm
Location: Washington


Return to Your Scripts

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.