Grow your CSS skills. Land your dream job.

PHP define function as array

  • # June 21, 2009 at 9:54 am

    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

    # June 21, 2009 at 10:18 am

    Not sure. You can pass an array to a php function and access it like any array.

    Code:
    $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().

    Code:
    help2(“one”, “two”, “three”);

    function help2() {
    foreach( func_get_args() as $arg) {
    echo $arg . “n”;
    }
    }

    # June 21, 2009 at 10:44 am

    that first idea is good idea!!!! just what I wanted thanks. Matt

    # June 21, 2009 at 11:12 am

    Thanks, but I got confused lol.

    This is what I have so far

    Code:
    < ?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.

    Code:
    < ?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

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".