title: Python to PHP - Base64 encode SHA256
body: <p>Can anyone help me with converting the following Python script to PHP?</p>
  
  <pre><code>data = json.dumps({'text': 'Hello world'})
  
  content_sha256 = base64.b64encode(SHA256.new(data).digest())
  </code></pre>
  
  <p>The value of content_sha256 should be</p>
  
  <blockquote>
    <p>oWVxV3hhr8+LfVEYkv57XxW2R1wdhLsrfu3REAzmS7k=</p>
  </blockquote>
  
  <p>I have tried to use the base64_encode function, and will only get the desired result if I use the string:</p>
  
  <pre><code>$data_string = "{\"text\": \"Hello world\"}";
  base64_encode(hash("sha256", $data_string, true));
  </code></pre>
  
  <p>but I want to get the desired result by using and array, not a quote-escaped string...</p>