Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5841433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:53:24+00:00 2026-05-22T11:53:24+00:00

Okay So I know this is super basic and I should know how to

  • 0

Okay So I know this is super basic and I should know how to do this but I’m blanking and having trouble finding the answer in Google. I have an include that has an array of variables for example

 $phrases["text"][1] = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?";
 $phrases["mp3"][1] = "http://example.com/file.mp3";

Then a function that gets the varibles:

function return_phrase($phrase_name="", $fallback="",$default ="text"){
    $next= (isset($default) && $default =="mp3") ? 'text' : 'mp3';  
    if(isset($tts_phrases[$default][$phrase_name])){
        return $phrases[$default][$phrase_name]);
    }
    else if(isset($tts_phrases[$next][$phrase_name])){
        return $phrases[$next][$phrase_name]);
    }

    else{
        return $fallback;
    }
}

The problem is that the $phrases arrays aren’t being sent to the function I can include the file in the function itself but I know that’s the wrong way to do it. I think I need to use $global just not sure how.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:53:24+00:00Added an answer on May 22, 2026 at 11:53 am

    Method 1: Pass $phrases, $tts_phrases as parameters

    function return_phrase(array $phrases, array $ttphrases, $phrase_name="", $fallback="",$default ="text"){
        $next= (isset($default) && $default =="mp3") ? 'text' : 'mp3';  
        if(isset($tts_phrases[$default][$phrase_name])){
            return $phrases[$default][$phrase_name]);
        }
        else if(isset($tts_phrases[$next][$phrase_name])){
            return $phrases[$next][$phrase_name]);
        }
    
        else{
            return $fallback;
        }
    }
    

    Method 2: Make $phrases, $tts_phrases global (bad!)

    function return_phrase($phrase_name="", $fallback="",$default ="text"){
        global $phrases, $tts_phrases;
        $next= (isset($default) && $default =="mp3") ? 'text' : 'mp3';  
        if(isset($tts_phrases[$default][$phrase_name])){
            return $phrases[$default][$phrase_name]);
        }
        else if(isset($tts_phrases[$next][$phrase_name])){
            return $phrases[$next][$phrase_name]);
        }
    
        else{
            return $fallback;
        }
    }
    

    Using global variables is a quick and easy fix, but once your application gets larger they become very hard to keep track of. For example, take this legacy code snippet that I have to deal with at work:

    function foo() {
         global $mysqldsn, $ldapdsn, $autologout_timer, $isMobileDevice, logout_fail_limit, $logout_fail_window, $lang, $project_contact_email, $project_contact_name ... (50 or 60 more global variables following)
         ...
     }
    

    Any time I am looking at one of the pages that just pulls one of those variables out of thin air, I have to Ctrl+F the whole project and make sure that every little change hasn’t messed up the whole app. When you keep your variables in local scope, you know exactly what you are changing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I know this question have been asked plenty of times already, but I
Okay. I know this looks like the typical Why didn't he just Google it
Okay I know I asked about this before, and the answer was basically cache
Okay so im working on this php image upload system but for some reason
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my
Okay, I need help. I'm usually pretty good at SQL queries but this one
Okay I know this is a really lame question because Starbasic is a really
Okay, I really know this has GOT to be the long way around doing
Basically, I'd like to know if this code is okay, <body id=some_id <!--[if lt
Okay, we know that the following two lines are equivalent - (0 == i)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.