Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts

    Arrays, functions, breaks and basic programmin logic question

    I cant figure how to escape function which creates array, and then goes to antoher function. Problem is that function calls that other function X times the array is created. Here's the logic
    PHP Code:
    function guess_where($1,$2,$3) {
     
    // for() function guesses numbers where 2, 5, 10, etc..
     //
    create_array($1//calling a function what creates array from numbers found
    }

    function 
    create_array($1){
    GLOBAL $
    2;
    GLOBAL $
    3;

    //the part where array is created

    use_array($array, $2, $3)
    }

    function 
    use_array($array, $2, $3){

    //beacouse of the logic of the first function this function is egzecuted
    //X number of times depending on the size of the array


    I can't figure out, how to CALL a function, only when the whole array is crated, instead that it goes through whole FOR loop calling create_array function every time..

    Here's my guess_where function logic

    PHP Code:
    function guess_where($1,$2,$3) {
    for(
    $a$a sizeof($2$a++) 

    $term1 //1st term
    $term2 //2nd term

    if ($term1 == $term2):
    create_array($1);
    endif; 


    Hope this isn't bothering you too much. And thanks for the help!

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    This is possibly the worst code I've ever seen :O

    What are you trying to accomplish, in broad terms?

  • #3
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    a function that will work on something, and when it doesn't have any more values to work with start another function...

  • #4
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Quote Originally Posted by matak View Post
    a function that will work on something, and when it doesn't have any more values to work with start another function...
    Start work with the same array you mean?

    PHP Code:
    function do_some_stuff_to_array($array)
    {
        foreach (
    $array as &$val)
        {
            
    // stuff == double each entry
            
    $val *= 2;    
        }
        return 
    do_some_more_stuff_to_array($array);
    }

    function 
    do_some_more_stuff_to_array($array)
    {
        foreach (
    $array as &$val)
        {
            
    // more stuff == decrement each entry
            
    --$val;
        }
        return 
    $array;
    }

    print_r(do_some_stuff_to_array(array(12345678910)))
    // Array ( [0] => 1 [1] => 3 [2] => 5 [3] => 7 [4] => 9 [5] => 11 [6] => 13 [7] => 15 [8] => 17 [9] => 19 ) 
    Post again if that's not what you're driving at... You went a little too broad for me :P I was trying to discover the purpose of all this in concrete terms. Like "I want to transform an array of integers into the sum of its elements' squares," but not exactly that, unless it's really what you want.
    Last edited by ralph l mayo; 06-03-2007 at 08:15 AM.

  • #5
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    I'm just trying to improve

    Also i think i have managed to solve the problem. Just using google for now to test my beginners search script, which needs a loooot more improvement.
    You can check it out at this link (my_test_link)
    Next step is to create a HIT counter, to explode search so that it looks for one word too, to improve my fileget_contents result.
    For few days now, i'm running a crawler bot from my localhost to kinda see weather it can help me to create a Database. And results are promising.

    Mostly i use simple functions, but as i'm kind of a PHP/Programmer newbie it all looks so wicked

    p.s. i didn't bother too much striping google results, so some of the queries might show none results. this is just for testing purposes


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •