Unholy Prayer Posted February 27, 2007 Share Posted February 27, 2007 Ok, I've seen in PHP programs such as PHPbb2 where they use I think arrays to use things like {SITE_NAME} instead of $sitename. I keep seeing things like 'RANK_IMAGE' => $rank_image, and what not. How do I do this? Link to comment https://forums.phpfreaks.com/topic/40293-questioni-think-about-arrays/ Share on other sites More sharing options...
fert Posted February 27, 2007 Share Posted February 27, 2007 $array=array("key"=>"value","key2"=>"value2"); Link to comment https://forums.phpfreaks.com/topic/40293-questioni-think-about-arrays/#findComment-194910 Share on other sites More sharing options...
Unholy Prayer Posted February 27, 2007 Author Share Posted February 27, 2007 Yeah, I didn't understand that at all. You're going to have to explain that a bit for me. Thanks. Link to comment https://forums.phpfreaks.com/topic/40293-questioni-think-about-arrays/#findComment-194912 Share on other sites More sharing options...
utexas_pjm Posted February 27, 2007 Share Posted February 27, 2007 It's an associateive array. In java they inherit from the java.util.Dictionary class which is kind of a good way to think about them. You have a key (think word) and a value think (definition). This allows you you to do things like this: <?php $dictionary = array('bird' => 'Something that flies', 'dog' => 'something that barks'); echo $dictionary['dog']; // prints: something that barks. ?> Best, Patrick Link to comment https://forums.phpfreaks.com/topic/40293-questioni-think-about-arrays/#findComment-194913 Share on other sites More sharing options...
Unholy Prayer Posted February 27, 2007 Author Share Posted February 27, 2007 Ok, So how do I get something like {SITE_NAME} to display a string that gets the site name from a database? If my code is $settings = mysql_query("select * from ubs_settings where id=1"); while($s=mysql_fetch_array($settings)) { $sitename=$s["sitename"]; $slogan=$s["slogan"]; } how would I make {SITE_NAME} to display $sitename? Link to comment https://forums.phpfreaks.com/topic/40293-questioni-think-about-arrays/#findComment-194919 Share on other sites More sharing options...
HaLo2FrEeEk Posted February 27, 2007 Share Posted February 27, 2007 From my understanding writing MODs for phpbb, you have to have the tpl files included, using a function. I wrote a mod that will display the user's theme next to their post in viewtopic.php, I added this to the associative array: 'POSTER_THEME' => $poster_style, Then, in the tpl file, I added this where I wanted the theme name to appear: {postrow.POSTER_THEME} postrow was the name of the array. I don't know anything about how to associate the template file and the associative array, I'm sure other people here do though. Link to comment https://forums.phpfreaks.com/topic/40293-questioni-think-about-arrays/#findComment-194925 Share on other sites More sharing options...
Unholy Prayer Posted February 27, 2007 Author Share Posted February 27, 2007 I'm not writing a mod for PHPbb, but so far I have 'SITE_NAME' => $sitename, as one of my things and I have {SITE_NAME} in one of my tpl files but it still displays {SITE_NAME} on the browser page. Link to comment https://forums.phpfreaks.com/topic/40293-questioni-think-about-arrays/#findComment-194926 Share on other sites More sharing options...
HaLo2FrEeEk Posted February 27, 2007 Share Posted February 27, 2007 I know you weren't writing a mod, I was describing how I used this, and it just so happened to be when I was writing a mod. sorry for the confusion. Link to comment https://forums.phpfreaks.com/topic/40293-questioni-think-about-arrays/#findComment-194942 Share on other sites More sharing options...
Unholy Prayer Posted February 27, 2007 Author Share Posted February 27, 2007 So how would I make {SITE_NAME} display the site's name if I were using this code: $variables = assign_block_vars('header', array( 'SITE_NAME' => $sitename, 'SLOGAN' => $slogan) ); Link to comment https://forums.phpfreaks.com/topic/40293-questioni-think-about-arrays/#findComment-195527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.