treehouse : what would you like to learn today?
Web Design Web Development iOS Development

PHP define function as array

  • You know you get arrays and you can define your own function, can and how do you merge them.

    So i define the function help() and use help(heart,blood,ab) to call it
  • Not sure. You can pass an array to a php function and access it like any array.
    	$arr = array(\"one\", \"two\", \"three\");

    help($arr);

    function help($args) {
    foreach ($args as $arg) {
    echo $arg . \"\n\";
    }
    }


    Or you can access the list of passed variables using fung_get_args().
    	help2(\"one\", \"two\", \"three\");

    function help2() {
    foreach( func_get_args() as $arg) {
    echo $arg . \"\n\";
    }
    }
  • that first idea is good idea!!!! just what I wanted thanks. Matt
  • Thanks, but I got confused lol.

    This is what I have so far

    <?php
    if( $_SERVER['HTTP_HOST'] == 'www.domain1.com') {
    header( 'Location: ../1' );
    }
    if( $_SERVER['HTTP_HOST'] == 'www.domain2.com') {
    header( 'Location: ../2' );
    }
    ?>


    I want to set it up so I don't need these wasted instructions. Something like this because I will have alot of domains.

    <?php

    //Define function here

    redirect('www.domain1.com','../1');
    redirect('www.domain2.com','../2');
    ?>


    BTW i know I cannot use redirect, but i'm not very creative atm. :D