jessicakennedy1028 icon

String to Array

jessicakennedy1028 | PRO | 09/09/18 01:22:36 PM UTC | 0 ⭐ | 307 👁️ | Never ⏰ | []
PHP |

950 B

|

None

|

0 👍

/

0 👎

    function stringtoArray($string = null, $keySep = null, $valSep = null) {
        $keySep == '' ? $keySep = '==' : $keySep;
        $valSep == '' ? $valSep = '&&' : $valSep;
        
        $chunks = array_chunk(preg_split('/('.$keySep.'|'.$valSep.')/', $string), 2);
        $defined = array_combine(array_column($chunks, 0), array_column($chunks, 1));
 
        if (is_array($defined)) {
            $output = $defined;
        }
        else {
            $output = '<p>Your string is malformed, here is a use of a define example:</p><p>$string="example'.$keySep.'a thing characteristic of its kind or illustrating a general rule.'.$valSep.'test'.$keySep.'a procedure intended to establish the quality, performance, or reliability of something, especially before it is taken into widespread use.'.$valSep.'demonstrate'.$keySep.'clearly show the existence or truth of (something) by giving proof or evidence."</p>';
        }
        return $output;
    }

Comments