Question: I am being passed inconsistent data. The problem is the individual rows of `$data_array` are not consistently in the same sequence but each has a reliable "text:" preceding the value. 

Each row contains about 120 elements of data. I only need 24 of those elements.

It's also possible one of the elements I need could be missing, such as "cost".

(I'm using php version 5.4)  

-- Task: 

Using $order\_array, create a new $data\_array\_new by reordering the data in each "row" into the same sequence as $order\_array.

If an elements is missing from a row insert "NA".

Once the elements are in the correct sequence the "text" is no longer required.

```
$order_array = array("price", "cost", "vol", "eps")
$data_array = Array (
    $one = Array ("cost":43.40, "vol":44000,   "eps":1.27,   "price":65.00),
    $two = Array ("eps":5.14,   "price":33.14, "vol":657000),
    $thr = Array ("vol":650000, "cost":66.67,  "eps":1.33,   "price":44.31),
);

```

The resulting ouput should appear with the data in this order: ("price", "cost", "vol", "eps")

```
$data_array_new = Array (
    $one = Array (65.00,43.40,44000,1.27),
    $two = Array (33.14,"NA",657000,5.14),
    $thr = Array (44.31,66.67,650000,1.33),
);

```

Answer: 
Of course you can. Just create an interface for the Fragment, let's say `FragmentCallback`, with your desired callback method, `onButtonClick()` for instance. In the `onAttached()` of your Fragment, cast the Activity to your new interface and store it in a variable `private FragmentCallback callback;`. Each Activity using this Fragment must implement this callback interface. Then call the callbacks `onButtonClick()` method in your Fragments `onButtonClick()` method. That's it - a very common pattern.
Yes you can!

```
if(getActivity() instanceOf ActivityA) {
    //do stuff related to ActivityA
} else if(getActivity() instanceOf ActivityB) {
    //do stuff related to ActivityB
}

```