Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The Matrix (Version 1.03)
#16
for my new code I check whether the array is associative or not and build the dropdown using it.
Otherwise the dropdown uses the labels only

Code:
* @param array $arr Array to check
    * @return boolean True is array is associative
    */
    public static function isAssoc($arr){
        return array_keys($arr) !== range(0, count($arr) - 1);
    }

Then build the dropdown with

Code:
if (!Arr::isAssoc($options)){
                    foreach($options as $item){
                        $this->value .= '        <option value="'.($item).'"';
                        if (($value)==($item)) $this->value .= " selected ";
                        $this->value .='>'.$item.'</option>';    
                    }
                } else {

                    foreach($options as $item=>$value2){
                        $this->value .= '        <option value="'.($item).'"';
                        if (($value)==($item)) $this->value .= " selected ";
                        $this->value .='>'.$value2.'</option>';    
                    }
                }

sorry its copy/pasted from new code, but you get the idea...
My Github Repos: Github
Website: DigiMute
Reply


Messages In This Thread
The Matrix (Version 1.03) - by Angryboy - 2013-06-24, 08:32:28
RE: The Matrix (Reloaded...OOP style) - by hameau - 2013-06-24, 19:44:34
RE: The Matrix (Reloaded...OOP style) - by Bigin - 2013-06-24, 21:58:43
RE: The Matrix (Reloaded...OOP style) - by Bigin - 2013-06-25, 00:23:54
RE: The Matrix (Reloaded...OOP style) - by evan70 - 2013-06-25, 23:35:32
RE: The Matrix (Reloaded...OOP style) - by n00dles101 - 2013-08-02, 03:14:52
RE: The Matrix (Version 1.03) - by RobA - 2013-08-21, 00:52:57
RE: The Matrix (Version 1.03) - by Angryboy - 2013-08-22, 07:35:26
RE: The Matrix (Version 1.03) - by datiswous - 2013-09-13, 08:24:25
RE: The Matrix (Version 1.03) - by xxdex - 2014-02-22, 08:08:13
RE: The Matrix (Version 1.03) - by xxdex - 2014-03-04, 05:42:23



Users browsing this thread: 3 Guest(s)