1

I have a class which pulls in Twitter feeds and amalgamates them, they are put into an array ,sorted and combined. I then need to convert the 'published' time from unix to human .

Within my class construct I have:

function __construct($inputs) {     

             $this->inputs = $inputs;
             $this->mergeposts();
             $this->sortbypublished($this->allPosts,'published');
             $this->unixToHuman('problem here');
             $this->output();
     }

SortbyPublished is

        function sortbypublished(&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
    $sorter[$ii]=$va[$key];
}
arsort($sorter);
foreach ($sorter as $ii => $va) {
    $ret[$ii]=$array[$ii];
}

    $this->sorted = $ret;

}

unixToHuman is :

public function unixToHuman($unixtime) {
            $posts['published'] =   date('Y-m-d H:i:s', $unixtime);
            }

My problem is I cannot work out what I need to enter into :

$this->unixToHuman('HERE');

Part of this I believe is due to my lack of understanding of PHP terminology, which is making it hard to find anything in the manual . Am I trying to reference the 'published' array?

What I need is the correct version of :

$this->sorted['published']

I hope this makes sense , any help at all , especially with the terminology greatly appreciated.

2 Answers 2

1

It looks like unixToHuman wants a timestamp. So you could use date(), or the timestamp of whatever time you want to convert to human readable time.

$this->unixToHuman(date());
Sign up to request clarification or add additional context in comments.

Comments

0

First off, the unixToHuman method needs to return a value, so let's do this:

public function unixToHuman($post) {
    $post['published'] =   date('Y-m-d H:i:s', $post['published']);
    return $post;
}

Then we can pass in our rows one at a time in your __construct method:

foreach ($this->sorted AS $idx => $row) {
    $this->sorted[$idx] = $this->unixToHuman($row);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.