1

I have this return value from the result of my query.

Array ( [0] => stdClass Object ( [password] => $2y$10$6D7S2gNkcDciJ7g5z/8sie79iV3FCGhGUCFCPHU3cNNdeUVUbLfQC ) )

and this is my query,

$sql = "SELECT `$fields` FROM `$table` WHERE `$column` {$operator} '$value'";
if($this->_query = $this->_pdo->prepare($sql)) {
    if($this->_query->execute()) {
        $this->_result = $this->_query->fetchAll(PDO::FETCH_OBJ);
        $this->_count = $this->_query->rowCount();
    } else {
        return $this->_error = true;
    }
}

print_r($this->_result);

Now what I want is to display or print only the array data which is this $2y$10$6D7S2gNkcDciJ7g5z/8sie79iV3FCGhGUCFCPHU3cNNdeUVUbLfQC

Thanks in advance for any help. :D

3
  • 2
    Do you understand how to access an object's property and an array's value? Commented Feb 4, 2014 at 4:49
  • If you want it to work with $this->_result[0]['password'] you should use PDO::FETCH_ASSOC. Commented Feb 4, 2014 at 4:52
  • you want to convert object to array? Commented Feb 4, 2014 at 4:52

1 Answer 1

1

Elements of array can be accessed using key in square brackets eg $arr[$key]. Property of an object is accessed by using a -> operator eg $this->name

If you just need to print, this is enough:

print_r($this->_result[0]->password);

Sign up to request clarification or add additional context in comments.

2 Comments

I edited your answer because indentation wasn't done in print_r($this->_result[0]->password); but then I discovered that you have backtick between password and ) - so I did a rollback to your original answer.
@Pengun You may accept the answer if you feel its helpful to you. :p

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.