Question: I need to open new WPA/WPA2 device from linux c code.
Now I create it manualy by using wpa\_supplicant

```
wpa_supplicant -iwlan0 -c connfig.conf -B

```

* How I can to start it from my code (without using system() )?
* What wpa\_supplicant interface is intended for this ?

Maybe, do you have any example ?
hanks in advance

Answer: 
Use a [reference](http://php.net/language.references) to refer to the latest known point in the array and update it with each step:

```
$ref = &$this->config;
$keys = explode('.', $name);
foreach ($keys as $idx => $key) {
    if (!is_array($ref)) {
        // reference does not refer to an array
        // this is a problem as we still have at least one key to go
    }
    if (!array_key_exists($key, $ref)) {
        // key does not exist
        // reaction depends on the operation
    }
    // update reference
    $ref = &$ref[$key];
}

```

The `if` branches depend on the operation. Here’s an example for the getter and setter:

```
public function get($name) {
    $ref = &$this->config;
    $keys = explode('.', $name);
    foreach ($keys as $idx => $key) {
        if (!is_array($ref)) {
            throw new Exception('key "'.implode('.', array_slice($keys, 0, $idx-1)).'" is not an array');
        }
        if (!array_key_exists($key, $ref)) {
            throw new Exception('key "'.implode('.', array_slice($keys, 0, $idx)).'" does not exist');
        }
        $ref = &$ref[$key];
    }
    return $ref;
}
public function set($name, $value) {
    $ref = &$this->config;
    $keys = explode('.', $name);
    foreach ($keys as $idx => $key) {
        if (!is_array($ref)) {
            throw new Exception('key "'.implode('.', array_slice($keys, 0, $idx)).'" is not an array but '.gettype($ref));
        }
        if (!array_key_exists($key, $ref)) {
            $ref[$key] = array();
        }
        $ref = &$ref[$key];
    }
    $ref = $value;
}

```
As you can see [here](http://php.net/manual/en/function.explode.php), the function `explode` takes the string and returns an array. So here is what you need to do:

```
public function set($name,$value)
    {
        $tmp = explode('.',$name); //$tmp will now contain an array, so if $name = 'site.keywords'
                                   //$tmp[0] will contain 'site' and $tmp[1] = 'keywords'
        //if you send 'otherthing' as $name, then $tmp[1] will have no value
        if(isset($tmp[1])){
                $this->config[$tmp[0]][$tmp[1]] = $value; // this is like saying  $this-config['site']['keywords'] = $value
        }
        else{
            $this->config[$tmp[0]] = $value; 
        }
    }

```

And for the get:

```
public function get($name)
    {
        $tmp = explode('.',$name);
        if(isset($tmp[1])){
            return $this->config[$tmp[0]][$tmp[1]];
        }
        else{
           return $this->config[$tmp[0]];
        }

    }

```