<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Returns a hexidecimal representation of this id</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongoid.set-state.html">MongoId::__set_state</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mongocode.html">MongoCode</a></div> <div class="up"><a href="class.mongoid.html">MongoId</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongoid.tostring" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoId::__toString</h1> <p class="verinfo">(PECL mongo >= 0.8.0)</p><p class="refpurpose"><span class="refname">MongoId::__toString</span> — <span class="dc-title">Returns a hexidecimal representation of this id</span></p> </div> <div class="refsect1 description" id="refsect1-mongoid.tostring-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><strong>MongoId::__toString</strong></span> ( <span class="methodparam">void</span> )</div> </div> <div class="refsect1 parameters" id="refsect1-mongoid.tostring-parameters"> <h3 class="title">Parameters</h3> <p class="para">This function has no parameters.</p> </div> <div class="refsect1 returnvalues" id="refsect1-mongoid.tostring-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> This id. </p> </div> <div class="refsect1 examples" id="refsect1-mongoid.tostring-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-1491"> <p><strong>Example #1 <span class="function"><strong>MongoId::__toString()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br />$m </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$collection </span><span style="color: #007700">= </span><span style="color: #0000BB">$m</span><span style="color: #007700">-></span><span style="color: #0000BB">selectDB</span><span style="color: #007700">(</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">)-></span><span style="color: #0000BB">selectCollection</span><span style="color: #007700">(</span><span style="color: #DD0000">"bar"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-></span><span style="color: #0000BB">insert</span><span style="color: #007700">(array( </span><span style="color: #DD0000">"x" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"y" </span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-></span><span style="color: #0000BB">insert</span><span style="color: #007700">(array( </span><span style="color: #DD0000">"x" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"y" </span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$cursor </span><span style="color: #007700">= </span><span style="color: #0000BB">$collection</span><span style="color: #007700">-></span><span style="color: #0000BB">find</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$r1 </span><span style="color: #007700">= </span><span style="color: #0000BB">$cursor</span><span style="color: #007700">-></span><span style="color: #0000BB">next</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$r2 </span><span style="color: #007700">= </span><span style="color: #0000BB">$cursor</span><span style="color: #007700">-></span><span style="color: #0000BB">next</span><span style="color: #007700">();<br /><br />echo </span><span style="color: #0000BB">$r1</span><span style="color: #007700">[</span><span style="color: #DD0000">"_id"</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$r2</span><span style="color: #007700">[</span><span style="color: #DD0000">"_id"</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> 49a7011a05c677b9a916612a 49a702d5450046d3d515d10d </pre></div> </div> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongoid.set-state.html">MongoId::__set_state</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mongocode.html">MongoCode</a></div> <div class="up"><a href="class.mongoid.html">MongoId</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>