Dragoa Posted June 20, 2008 Share Posted June 20, 2008 I don't know what to call this, so I can't really do any searching for it, but basically what I want to do is if I pass a function a variable, to have it take that variable, and if I don't, take a default one. What is basically happening is I've got a header class which makes some change for my navigation for the site, and I don't want it to do for a certain page, but I want it to do this for every other page. But to make this easier, code below shows my desired result. printCommand("Test"); //Would print Test to the screen. printCommand(); //Would print Default to the screen. printCommand("Test2"); //Would print Test2 to the screen. I don't really wanna do any sort of hardcoding in these pages[so I can't just make an exception in the class itself], since it's bad style and essentially makes any sort of modification extremely tedious. Any help is greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/111160-solved-default-variable-setting/ Share on other sites More sharing options...
widox Posted June 20, 2008 Share Posted June 20, 2008 The most basic way would to have something like function doSomething($param = 'default value') { // function body } so if you just call doSomething() $param would be 'default value', but if you called doSomething('no use this'); $param would be 'no use this' instead. Is that what your looking for? Link to comment https://forums.phpfreaks.com/topic/111160-solved-default-variable-setting/#findComment-570524 Share on other sites More sharing options...
Dragoa Posted June 20, 2008 Author Share Posted June 20, 2008 *smacks head* Was the first thing I tried, but I modified the wrong page when I was doing my test....All works now. Link to comment https://forums.phpfreaks.com/topic/111160-solved-default-variable-setting/#findComment-570527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.