Question: I tried getting the answers in similar questions, everyone says that it's not necessary, but if $e$ is the identity element for any binary operation $\*$, which is not associative and commutative, how can

$$a\*e=a=e\*a$$

when it is not commutative, i.e. $a\*b \ne b\*a$?

Even if we get a value by solving $a\*e=a$. Will we get the same value by solving
$e\*a=a$ ?
Please provide an example.

Answer: 
Without looking for esoteric and/or ad hoc examples, there is one you are certainly familiar with. The identity matrix is the identity element for matrix multiplication, which is not commutative. We have $A\,I=I\,A=A $ while in general $A\,B \neq B\,A $.
> 
> Can a binary operation have an identity element when it is not associative and commutative?
> 
> 
> 

Yes. Any non-commutative [**loop**](http://ericmoorhouse.org/pub/bol/) is an example of such algebraic structure. I am surprised that, searching the word *loop* with `Ctrl + F` in this page just before answering, I found only one occurrence in the comment by Arthur.

---

> 
> (...) how can
> 
> 
> $$a\*e=a=e\*a$$
> 
> 
> when it is not commutative (...) ?
> 
> 
> 

As in the accepted answer, the operation $\*$ is by definition **commutative** on the set $A$, **if and only if**
$$
a\*b=b\*a
$$
**for all** $a,b\in A$.

No surprise if, in a given operation on a given set $A$, only some elements of $A$ commute with all the others: in a non-commutative binary operation with two-sided identity, the identity element commutes with all the others elements. Indeed, the definition of **identity element** $e$ for the binary operation $\*$ on a set $A$ states:
$$
a\*e=a=e\*a,\quad\forall\,a\in A.
$$

---

> 
> Please provide an example.
> 
> 
> 

Of course `:)` And, further, we can create without too much effort an example which is even less than a loop. The finite magma of order $4$ given by the Cayley table
\begin{array}{c|cccc}
\* & 1 & 2 & 3 & 4\\
\hline
1 & \color{red}{1} & \color{red}{2} & \color{red}{3} & \color{red}{4}\\
2 & \color{red}{2} & 4 & 3 & 3\\
3 & \color{red}{3} & 3 & 4 & 2\\
4 & \color{red}{4} & 1 & 1 & 1\\
\end{array}
has the two-sided identity element $1$ while cancellation and division do not hold, it is not commutative since - e.g. - $2\*4\ne 4\*2$ and it is not even associative:
$$
(2\*3)\*4=3\*4=2\ne 4=2\*2=2\*(3\*4).
$$