TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   question on functions (http://www.talkphp.com/absolute-beginners/2111-question-functions.html)

sarmenhb 01-27-2008 07:41 AM

question on functions
 
if i wrote something like this

Code:


<?php

function names($fname,$lname,$mname)
{

return array( '$FirstName' => '$fname',
              '$LastName' => '$lname',
              '$MiddleName' => '$mname');
}

names('sarmenhb','sarmenhb','sarmenhb');
names('a','b','c');
names('c','d','e');

?>


how can i output what the names function contains or how can i make use of this.

im beginning to think that arrays can be similar to ram like a temporary database or information storage that is volatile ;-)

Orc 01-27-2008 08:17 AM

Quote:

Originally Posted by sarmenhb (Post 9759)
if i wrote something like this

Code:


<?php

function names($fname,$lname,$mname)
{

return array( '$FirstName' => '$fname',
              '$LastName' => '$lname',
              '$MiddleName' => '$mname');
}

names('sarmenhb','sarmenhb','sarmenhb');
names('a','b','c');
names('c','d','e');

?>


how can i output what the names function contains or how can i make use of this.

im beginning to think that arrays can be similar to ram like a temporary database or information storage that is volatile ;-)


What are you trying to do? You should make that a var then iterate the variable using foreach, and return the new iterated var. Otherwise it'll just output "Array"

sarmenhb 01-27-2008 08:26 AM

Quote:

Originally Posted by Orc (Post 9760)
What are you trying to do? You should make that a var then iterate the variable using foreach, and return the new iterated var. Otherwise it'll just output "Array"


im reading this book and its starting to talk about OOP and its relation functions to classes and it showed that example.

i thought it was pretty cool. and wondered how i can make use of it.

Orc 01-27-2008 08:30 AM

Quote:

Originally Posted by sarmenhb (Post 9761)
im reading this book and its starting to talk about OOP and its relation functions to classes and it showed that example.

i thought it was pretty cool. and wondered how i can make use of it.

you could try multidimensional arrays
PHP Code:

function array_multidim()
{
$array = array(
        array(
                
=> "Hello World!"
)
);
  
// Iterative Construct
  
foreach ($array as $a => $data)
  {

   return 
$a[$data];
  }




All times are GMT. The time now is 06:32 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0