0
$server_loc = $_SERVER['REQUEST_URI']; 

$locations = array( '/aiesec/ar/',
                    '/aiesec/ar/volunteer-abroad/',
                    '/aiesec/ar/about/',
                    '/aiesec/ar/working-abroad/',
                    '/aiesec/ar/stories/'
                  );

foreach ($locations as $loc) {

    if($server_loc == $loc) {
        $translate['apply'] = "قدم الآن";
        $translate['recent_stories'] = "قصص الأخيرة";
        $translate['instagram_feed'] = "إينستاجرام تغذية";
    } else {
        $translate['apply'] = "APPLY NOW";
        $translate['recent_stories'] = "RECENT STORIES";
        $translate['instagram_feed'] = "INSTAGRAM FEED";
    }

}

Hey all, Trying to get this simple code to work.

It's a very simple translation for a small website but for some reason, it refuses to work.

$server_loc works, as it'll echo '/aiesec/ar/' when I'm on the homepage.

Nazar Abubaker
  • 495
  • 3
  • 7
  • 17
  • You are setting the data in $translate in _every_ loop iteration, so of course only what you set in the _last_ iteration "survives" and is available after the loop. – CBroe Mar 13 '17 at 08:59
  • Possible duplicate of [How can I check if an array contains a specific value in php?](https://stackoverflow.com/questions/8881676/how-can-i-check-if-an-array-contains-a-specific-value-in-php) – mickmackusa Feb 19 '18 at 13:08

1 Answers1

1

Why don't you use in_array

if(in_array($server_loc,$locations)){
        $translate['apply'] = "قدم الآن";
        $translate['recent_stories'] = "قصص الأخيرة";
        $translate['instagram_feed'] = "إينستاجرام تغذية";

}
NID
  • 3,238
  • 1
  • 17
  • 28