PHP - How To Use Declare() Construct ?
hi, cane somebody please explain how to use the declare contruct of PHP
some code snippets may help..thanks in advance Similar TutorialsI am looking at the following code snippet:
functioncall(array(),$variable)
I've looked everywhere, but cannot find what this is supposed to mean.
In the function that is called I see
function functioncall($var = array(), $var1 = array())
Is this some kind of cast??
Thanks!
Struggling to get my head round this, may be really simple and im just not seeing it because im tired, but why does the following code generate two files? <?php class x { var $val = ''; var $cfg = array(); public function __construct($somevalue) { $this->val = $somevalue; file_put_contents(rand(0,1000).'init','null'); } public function addcfg($name,$value) { $this->cfg[$name] = $value; } } //Create $somevalue = 'abc'; $x = new x($somevalue); //Add database config $x->addcfg('name','dbname'); $x->addcfg('user','dbuser'); $x->addcfg('pass','dbpass'); Hi Chaps, I have a while loop which produces a couple of variables: do { $L_NAME.$i = 'Item 1'; $L_NUMBER.$i = '0001'; $L_QTY.$i = '1'; $L_AMT.$i = 10.50; $NVP.$i = "L_NAME.$i.= .$L_NAME.$i.&L_NUMBER.$i. = .$L_NUMBER.$i.&"; } while($i == $items); Basically what I need to do is contruct a parameter made up of all the $NVP variables. I've a feeling that I would need to add each variable to an array and then use a foreach statement, but I'm not 100% sure. I'd be interested in the correct way to go about this, any comments welcome! Hi all. I'm just getting my feet wet with OOPHP. My question is "why have a setter method when you can just use the __construct method to set everything?" and "would you need a separate setter method for each attribute of an object?"(i.e. set_first, set_last, set_gender, etc.) The code... <?php class person{ var $first; var $last; var $gender; function __construct($first,$last,$gender){ $this->first=$first; $this->last=$last; $this->gender=$gender; } function set_first($new_name){ $this->first=$new_name; } function get_person(){ return $this->first . $this->last . $this->gender; } } ?> Hey All, I'm tryin to make a log-in system for multiple usernames and passwords, but I don't really know how many if statements i'd need for it.. I'm also a noob.. Code: [Select] <?php session_start(); $users = array("user1" =>"3202", "user2" =>"2002", "user3" =>"1061", "user4"=>"1400", "user5"=>"1001"); if($_REQUEST['username'] == "infs" && $_REQUEST['password'] == "3202"){ $_SESSION['username'] = "user1" ; $_SESSION['password'] = "3202" ; $_SESSION['username'] = "user2" ; $_SESSION['password'] = "2002" ; $_SESSION['username'] = "user5" ; $_SESSION['password'] = "1001" ; $_SESSION['username'] = "user3" ; $_SESSION['password'] = "1061" ; $_SESSION['username'] = "user4" ; $_SESSION['password'] = "1400" ; header("Location: home.php "); }else{ After checking if the matching username and password exist in my array then save them in a session... What's the best way of doing it? Can you set a variable like so: Function something(bob = true) { } I'm started learn PHP about 7 days.I want to know>>is this possible to declare a Variable like $password="Phpfreaks"??? Howdy colleagues,
I have noticed some programmers re-declare their variables before using them. Like so:
$name = ''; $name = 'Elizabeth';First of all, why do they do that? Variables are being re-written with each "=" anyways. Secondly, do you believe this is better than just doing: $name = 'Elizabeth';Thank you hi good day, im a little bit confuse. what i want to do is instead of $username = $_POST['username']; is to transform it into OOP? please help me. thanks. Hi, I have these variables for pages I navigate to because I pass them in the query string. However, I need a variable for the homepage (index.php), before any query string is created. I cant declare a vari $_GET['intro'] ; $_GET['about'] ; $_GET['contact'] ; However, I need a variable for the homepage (index.php), before any query string is created. I cant declare a variable in index.php because it will be used throughout the entire website. I also cant declare the variable in home.php (the bulk content of the homepage) because I need to use the variable before home.php is included. Is their a trick for this? Thanks! I keep running into a bunch of error when I declare the page variable in my model. What syntax do I need to use throughout the class? Code: [Select] <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Header_Model extends CI_Model{ var $page = substr(end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF'])), 0, -4); function get_page_name() { $this->load->library('common'); $page_names = $this->common->page_names(); $title = (array_key_exists($page, $page_names) !== false) ? $page_names[$page]: ''; if (array_key_exists($page, $page_names) !== false) { $title .= " | Jason Biondo"; } return $title; } function get_js_page_file() { if (file_exists("./assets/js/pages/${page}.js")) { $javascript = "<script type=\"text/javascript\" src=\"./js/pages/${page}.js\"></script>"; } return $javascript; } } According to woorank.com my page shows the following. Language Declared: Missing Detected: en I have used Code: [Select] header('content-type: text/html; charset=utf-8'); but do not know how I declare the language. also how do i specify Language/character encoding how is this done ? I tried these below, Code: [Select] class Site extends Controller { function Site() { public $data = Array(); } } but it fail? Thanks in advanced. I am running through a tutorial and I am getting an error based on a the concatication operator on my output. Below is my code. As you can see I am echoing $display_block .= "<p>$title<br>$rec_label<br>.... If I send this as-is I get this error: Notice: Undefined variable: display_block in C:\wamp\www\php\php_mysql\sel_byid.php on line 36 I can resolve the error by placing this before the while loop: $display_block = ""; Is there a better way to output the concatenation.= so I don't need to do this weird fix? while ($row = mysql_fetch_array($result)) { $id = $row['id']; $format = $row['format']; $title = stripslashes($row['title']); $artist_fn = stripslashes($row['artist_fn']); $artist_ln = stripslashes($row['artist_ln']); $rec_label = stripslashes($row['rec_label']); $my_notes = stripslashes($row['my_notes']); $date_acq = $row['date_acq']; if ($artist_fn != "") { $artist_fullname = trim("$artist_fn $artist_ln"); } else { $artist_fullname = trim("$artist_ln"); } if ($date_acq == "0000-00-00") { $date_acq = "[unknown]"; } $display_block .= "<p>$title<br>$rec_label<br>$artist_fullname<br>$my_notes<br>$date_acq<br>$format</p>"; |